diff options
| author | Francois Berder <[email protected]> | 2025-12-15 12:34:16 +0100 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-01-02 15:51:54 -0600 |
| commit | cec36b777a56b61c347447c12e61a9d1c425f396 (patch) | |
| tree | 8decd923a8456cb2579397c85eb57a8679be5af6 /fs | |
| parent | 9ac621e671858bf0b80dd26b883f3781cc5acb34 (diff) | |
fs: ext4fs: Free memory while handling errors
If zalloc fails, one needs to free memory previously
allocated in the function. This commit makes sure that
we do not leak any memory.
Signed-off-by: Francois Berder <[email protected]>
Fixes: ed34f34dbaf2 ("ext4fs write support")
Acked-by: Quentin Schulz <[email protected]>
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/ext4/ext4_common.c | 6 | ||||
| -rw-r--r-- | fs/ext4/ext4_journal.c | 4 | ||||
| -rw-r--r-- | fs/ext4/ext4_write.c | 4 |
3 files changed, 10 insertions, 4 deletions
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 8e6531fa3f0..9e1d574e5b1 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -727,8 +727,12 @@ static int parse_path(char **arr, char *dirname) /* add each path entry after root */ while (token != NULL) { arr[i] = zalloc(strlen(token) + 1); - if (!arr[i]) + if (!arr[i]) { + while (i--) + free(arr[i]); + return -ENOMEM; + } memcpy(arr[i++], token, strlen(token)); token = strtok(NULL, "/"); } diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c index 868a2c1804a..3a2e9f30c12 100644 --- a/fs/ext4/ext4_journal.c +++ b/fs/ext4/ext4_journal.c @@ -256,8 +256,10 @@ void ext4fs_push_revoke_blk(char *buffer) } node->content = zalloc(fs->blksz); - if (node->content == NULL) + if (!node->content) { + free(node); return; + } memcpy(node->content, buffer, fs->blksz); if (first_node == true) { diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c index 5b290f0d80d..2b8ed1cd110 100644 --- a/fs/ext4/ext4_write.c +++ b/fs/ext4/ext4_write.c @@ -205,7 +205,7 @@ static void delete_double_indirect_block(struct ext2_inode *inode) di_buffer = zalloc(fs->blksz); if (!di_buffer) { printf("No memory\n"); - return; + goto fail; } dib_start_addr = di_buffer; blknr = le32_to_cpu(inode->b.blocks.double_indir_block); @@ -304,7 +304,7 @@ static void delete_triple_indirect_block(struct ext2_inode *inode) tigp_buffer = zalloc(fs->blksz); if (!tigp_buffer) { printf("No memory\n"); - return; + goto fail; } tib_start_addr = tigp_buffer; blknr = le32_to_cpu(inode->b.blocks.triple_indir_block); |
