fsck.f2fs: deal with realloc size and realloc failure
authorLiu Xue <liuxueliu.liu@huawei.com>
Mon, 14 Dec 2015 11:31:28 +0000 (11:31 +0000)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 14 Dec 2015 18:11:48 +0000 (10:11 -0800)
Deal with realloc failure to avoid memory leak and memory free,
and assert realloc size to avoid double free for tree_mark.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c

index 63ee914..58786f2 100644 (file)
@@ -892,7 +892,9 @@ static void print_dentry(__u32 depth, __u8 *name,
 
        if (tree_mark_size <= depth) {
                tree_mark_size *= 2;
+               ASSERT(tree_mark_size != 0);
                tree_mark = realloc(tree_mark, tree_mark_size);
+               ASSERT(tree_mark != NULL);
        }
 
        if (last_de)
@@ -1256,6 +1258,7 @@ void fsck_init(struct f2fs_sb_info *sbi)
 
        build_sit_area_bitmap(sbi);
 
+       ASSERT(tree_mark_size != 0);
        tree_mark = calloc(tree_mark_size, 1);
        ASSERT(tree_mark != NULL);
 }