]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fs: ext4fs: Free memory while handling errors
authorFrancois Berder <fberder@outlook.fr>
Mon, 15 Dec 2025 11:34:16 +0000 (12:34 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 2 Jan 2026 21:51:54 +0000 (15:51 -0600)
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: ed34f34dbaf2 ("ext4fs write support")
Acked-by: Quentin Schulz <quentin.schulz@cherry.de>
fs/ext4/ext4_common.c
fs/ext4/ext4_journal.c
fs/ext4/ext4_write.c

index 8e6531fa3f0c3755bc7535c12fbb3aa40835a86b..9e1d574e5b144a903888320e4692ec0a546aaf76 100644 (file)
@@ -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, "/");
        }
index 868a2c1804a5bc7eca6ac271229e890e291144b5..3a2e9f30c125192ebae8af5d470ce0033e384ebb 100644 (file)
@@ -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) {
index 5b290f0d80d43a65fc74b4c0c06269f35b7075cf..2b8ed1cd110c25b105ea91837daed1af23c0648a 100644 (file)
@@ -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);