]> git.sur5r.net Git - u-boot/commitdiff
ext4: Fix memory leak in case of failure
authorStefan Brüns <stefan.bruens@rwth-aachen.de>
Tue, 6 Sep 2016 02:36:51 +0000 (04:36 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 23 Sep 2016 13:02:41 +0000 (09:02 -0400)
temp_ptr should always be freed, even if the function is left via
goto fail.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
fs/ext4/ext4_write.c

index 8554793f4f7da0c1c794c09c2761aff25de1d404..c55e2528e344264a01d96c6232a4a96701d476d3 100644 (file)
@@ -974,7 +974,6 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
                        sizeof(struct ext2_inode));
                if (ext4fs_put_metadata(temp_ptr, parent_itable_blkno))
                        goto fail;
-               free(temp_ptr);
        } else {
                /*
                 * If parent and child fall in same inode table block
@@ -985,7 +984,6 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
                gd_index--;
                if (ext4fs_put_metadata(temp_ptr, itable_blkno))
                        goto fail;
-               free(temp_ptr);
        }
        ext4fs_update();
        ext4fs_deinit();
@@ -996,6 +994,7 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
        fs->curr_inode_no = 0;
        free(inode_buffer);
        free(g_parent_inode);
+       free(temp_ptr);
        g_parent_inode = NULL;
 
        return 0;
@@ -1003,6 +1002,7 @@ fail:
        ext4fs_deinit();
        free(inode_buffer);
        free(g_parent_inode);
+       free(temp_ptr);
        g_parent_inode = NULL;
 
        return -1;