From: David Sterba Date: Tue, 13 Sep 2016 09:26:06 +0000 (+0200) Subject: btrfs-progs: improve error handling in clone_inode_rec X-Git-Tag: upstream/4.16.1~1252 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea84d54121c228d0526404a97ac0cdd197f46ccb;p=platform%2Fupstream%2Fbtrfs-progs.git btrfs-progs: improve error handling in clone_inode_rec Cleanup the rb_tree. Signed-off-by: David Sterba --- diff --git a/cmds-check.c b/cmds-check.c index 327a687..e53751c 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -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) {