]> git.sur5r.net Git - u-boot/commitdiff
ext4: Fix memory leak of journal buffer if block is updated multiple times
authorStefan Brüns <stefan.bruens@rwth-aachen.de>
Tue, 6 Sep 2016 02:36:56 +0000 (04:36 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 23 Sep 2016 13:02:44 +0000 (09:02 -0400)
If the same block is updated multiple times in a row during a single
file system operation, gd_index is decremented to use the same journal
entry again. Avoid loosing the already allocated buffer.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
fs/ext4/ext4_journal.c

index cf14049c32931465630ab4e3832f3816226c7a15..5a25be4c8ac2c5871929f9c1cf07c0eaf2663b70 100644 (file)
@@ -190,7 +190,11 @@ int ext4fs_put_metadata(char *metadata_buffer, uint32_t blknr)
                printf("Invalid input arguments %s\n", __func__);
                return -EINVAL;
        }
-       dirty_block_ptr[gd_index]->buf = zalloc(fs->blksz);
+       if (dirty_block_ptr[gd_index]->buf)
+               assert(dirty_block_ptr[gd_index]->blknr == blknr);
+       else
+               dirty_block_ptr[gd_index]->buf = zalloc(fs->blksz);
+
        if (!dirty_block_ptr[gd_index]->buf)
                return -ENOMEM;
        memcpy(dirty_block_ptr[gd_index]->buf, metadata_buffer, fs->blksz);