btrfs-progs: skip erroneous free before initialization
authorGui Hecheng <guihc.fnst@cn.fujitsu.com>
Thu, 13 Mar 2014 05:01:31 +0000 (13:01 +0800)
committerChris Mason <clm@fb.com>
Fri, 21 Mar 2014 16:51:31 +0000 (09:51 -0700)
If the list is not initialized, don't try to free it.
Otherwise it will cause segmentfault.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
mkfs.c

diff --git a/mkfs.c b/mkfs.c
index 472c0b8..dbd83f5 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -965,7 +965,7 @@ static int make_image(char *source_dir, struct btrfs_root *root, int out_fd)
        ret = lstat(source_dir, &root_st);
        if (ret) {
                fprintf(stderr, "unable to lstat the %s\n", source_dir);
-               goto fail;
+               goto out;
        }
 
        INIT_LIST_HEAD(&dir_head.list);
@@ -987,6 +987,7 @@ fail:
                list_del(&dir_entry->list);
                free(dir_entry);
        }
+out:
        fprintf(stderr, "Making image is aborted.\n");
        return -1;
 }