Btrfs-progs: fail gracefully on error from open_ctree()
authorIlya Dryomov <idryomov@gmail.com>
Mon, 12 Dec 2011 18:00:25 +0000 (20:00 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 12 Dec 2011 18:00:25 +0000 (20:00 +0200)
Error checking block got moved mistakenly exposing us to a potential
segmentation fault.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
mkfs.c

diff --git a/mkfs.c b/mkfs.c
index e3ced195bb7e96cde10fa9d5e390f991354846c3..2085ae1e97a259612cade73cc5e672845867ff9c 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -1328,7 +1328,12 @@ int main(int ac, char **av)
                fprintf(stderr, "error during mkfs %d\n", ret);
                exit(1);
        }
+
        root = open_ctree(file, 0, O_RDWR);
+       if (!root) {
+               fprintf(stderr, "ctree init failed\n");
+               exit(1);
+       }
        root->fs_info->alloc_start = alloc_start;
 
        ret = make_root_dir(root, mixed);
@@ -1343,10 +1348,6 @@ int main(int ac, char **av)
                goto raid_groups;
 
        btrfs_register_one_device(file);
-       if (!root) {
-               fprintf(stderr, "ctree init failed\n");
-               return -1;
-       }
 
        zero_end = 1;
        while(ac-- > 0) {