mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
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 <fberder@outlook.fr>
Fixes: ed34f34dba ("ext4fs write support")
Acked-by: Quentin Schulz <quentin.schulz@cherry.de>
This commit is contained in:
committed by
Tom Rini
parent
9ac621e671
commit
cec36b777a
@@ -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, "/");
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user