btrfs-progs: improve error handling in clone_inode_rec
authorDavid Sterba <dsterba@suse.com>
Tue, 13 Sep 2016 09:26:06 +0000 (11:26 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 3 Oct 2016 09:33:15 +0000 (11:33 +0200)
Cleanup the rb_tree.

Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c

index 327a687..e53751c 100644 (file)
@@ -659,6 +659,7 @@ static struct inode_record *clone_inode_rec(struct inode_record *orig_rec)
        struct inode_backref *tmp;
        struct orphan_data_extent *src_orphan;
        struct orphan_data_extent *dst_orphan;
+       struct rb_node *rb;
        size_t size;
        int ret;
 
@@ -691,10 +692,21 @@ static struct inode_record *clone_inode_rec(struct inode_record *orig_rec)
                list_add_tail(&dst_orphan->list, &rec->orphan_extents);
        }
        ret = copy_file_extent_holes(&rec->holes, &orig_rec->holes);
-       BUG_ON(ret < 0);
+       if (ret < 0)
+               goto cleanup_rb;
 
        return rec;
 
+cleanup_rb:
+       rb = rb_first(&rec->holes);
+       while (rb) {
+               struct file_extent_hole *hole;
+
+               hole = rb_entry(rb, struct file_extent_hole, node);
+               rb = rb_next(rb);
+               free(hole);
+       }
+
 cleanup:
        if (!list_empty(&rec->backrefs))
                list_for_each_entry_safe(orig, tmp, &rec->backrefs, list) {