btrfs-progs: catch memory allocation failure from alloc_tree_backref
authorDavid Sterba <dsterba@suse.com>
Wed, 6 Jan 2016 14:52:11 +0000 (15:52 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 12 Jan 2016 14:02:50 +0000 (15:02 +0100)
Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

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

index bc594d5..8452fc6 100644 (file)
@@ -4354,6 +4354,9 @@ static struct tree_backref *alloc_tree_backref(struct extent_record *rec,
                                                u64 parent, u64 root)
 {
        struct tree_backref *ref = malloc(sizeof(*ref));
+
+       if (!ref)
+               return NULL;
        memset(&ref->node, 0, sizeof(ref->node));
        if (parent > 0) {
                ref->parent = parent;
@@ -4660,8 +4663,10 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
        }
 
        back = find_tree_backref(rec, parent, root);
-       if (!back)
+       if (!back) {
                back = alloc_tree_backref(rec, parent, root);
+               BUG_ON(!back);
+       }
 
        if (found_ref) {
                if (back->node.found_ref) {