btrfs: fix memory leak in update_space_info failure path
authorJeff Mahoney <jeffm@suse.com>
Wed, 17 May 2017 13:49:37 +0000 (09:49 -0400)
committerSasha Levin <alexander.levin@verizon.com>
Mon, 26 Jun 2017 02:02:19 +0000 (22:02 -0400)
[ Upstream commit 896533a7da929136d0432713f02a3edffece2826 ]

If we fail to add the space_info kobject, we'll leak the memory
for the percpu counter.

Fixes: 6ab0a2029c (btrfs: publish allocation data in sysfs)
Cc: <stable@vger.kernel.org> # v3.14+
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
fs/btrfs/extent-tree.c

index 2771bc32dbd933e2ed8aec770bd54510a590d783..1d8b3f8c36549d63d458e22b7e35bb1ad654e81f 100644 (file)
@@ -3732,6 +3732,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
                                    info->space_info_kobj, "%s",
                                    alloc_name(found->flags));
        if (ret) {
+               percpu_counter_destroy(&found->total_bytes_pinned);
                kfree(found);
                return ret;
        }