btrfs-progs: catch memory allocation failure from alloc_data_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 8452fc6..266451a 100644 (file)
@@ -4413,6 +4413,9 @@ static struct data_backref *alloc_data_backref(struct extent_record *rec,
                                                u64 max_size)
 {
        struct data_backref *ref = malloc(sizeof(*ref));
+
+       if (!ref)
+               return NULL;
        memset(&ref->node, 0, sizeof(ref->node));
        ref->node.is_data = 1;
 
@@ -4725,9 +4728,11 @@ static int add_data_backref(struct cache_tree *extent_cache, u64 bytenr,
         */
        back = find_data_backref(rec, parent, root, owner, offset, found_ref,
                                 bytenr, max_size);
-       if (!back)
+       if (!back) {
                back = alloc_data_backref(rec, parent, root, owner, offset,
                                          max_size);
+               BUG_ON(!back);
+       }
 
        if (found_ref) {
                BUG_ON(num_refs != 1);