summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Brüns <stefan.bruens@rwth-aachen.de>2016-09-06 05:36:56 +0300
committerDongjin Kim <tobetter@gmail.com>2020-02-10 16:44:41 +0300
commit2b1e1eaa3d8198f5f37f8252b46ea73a64628e3a (patch)
tree86ad4facdeb58f5c5d7ce1e08be16cd26c486a80
parented8d7675e16468c467182f6472a788f32d48f3b7 (diff)
downloadu-boot-2b1e1eaa3d8198f5f37f8252b46ea73a64628e3a.tar.xz
ext4: Fix memory leak of journal buffer if block is updated multiple times
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>
-rw-r--r--fs/ext4/ext4_journal.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c
index cf14049c32..5a25be4c8a 100644
--- a/fs/ext4/ext4_journal.c
+++ b/fs/ext4/ext4_journal.c
@@ -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);