btrfs-progs: Fix memory leak in write_raid56_with_parity
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 24 Oct 2016 02:43:32 +0000 (10:43 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 11 Nov 2016 15:23:30 +0000 (16:23 +0100)
Ebs and pointers are allocated, but if any of the allocation failed, we
should free the allocated memory.

Resolves-Coverity-CID: 1374101
Resolves-Coverity-CID: 1374100
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
volumes.c

index c128472..e39f21e 100644 (file)
--- a/volumes.c
+++ b/volumes.c
@@ -2143,8 +2143,11 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
 
        ebs = malloc(sizeof(*ebs) * multi->num_stripes);
        pointers = malloc(sizeof(*pointers) * multi->num_stripes);
-       if (!ebs || !pointers)
+       if (!ebs || !pointers) {
+               free(ebs);
+               free(pointers);
                return -ENOMEM;
+       }
 
        if (stripe_len > alloc_size)
                alloc_size = stripe_len;