Btrfs, fix memory leaks in error paths
authorJiri Slaby <jslaby@suse.cz>
Wed, 6 Jan 2010 16:57:22 +0000 (16:57 +0000)
committerChris Mason <chris.mason@oracle.com>
Mon, 18 Jan 2010 01:40:20 +0000 (20:40 -0500)
Stanse found 2 memory leaks in relocate_block_group and
__btrfs_map_block. cluster and multi are not freed/assigned on all
paths. Fix that.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: linux-btrfs@vger.kernel.org
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/relocation.c
fs/btrfs/volumes.c

index a9728680eca8ed299deb7fc322be97deeeb6f51b..ed3e4a2ec2c833b3aac4faf6143c4c3f22584b3e 100644 (file)
@@ -3281,8 +3281,10 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
                return -ENOMEM;
 
        path = btrfs_alloc_path();
-       if (!path)
+       if (!path) {
+               kfree(cluster);
                return -ENOMEM;
+       }
 
        rc->extents_found = 0;
        rc->extents_skipped = 0;
index 198cff28766d494f3a919673775fe679d560722f..220dad5db017fcd928e01eeaea010ed78300a235 100644 (file)
@@ -2649,8 +2649,10 @@ again:
        em = lookup_extent_mapping(em_tree, logical, *length);
        read_unlock(&em_tree->lock);
 
-       if (!em && unplug_page)
+       if (!em && unplug_page) {
+               kfree(multi);
                return 0;
+       }
 
        if (!em) {
                printk(KERN_CRIT "unable to find logical %llu len %llu\n",