]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
btrfs: sysfs: Fix error path kobject memory leak
authorTobin C. Harding <tobin@kernel.org>
Mon, 13 May 2019 03:39:11 +0000 (13:39 +1000)
committerDavid Sterba <dsterba@suse.com>
Thu, 16 May 2019 12:31:01 +0000 (14:31 +0200)
If a call to kobject_init_and_add() fails we must call kobject_put()
otherwise we leak memory.

Calling kobject_put() when kobject_init_and_add() fails drops the
refcount back to 0 and calls the ktype release method (which in turn
calls the percpu destroy and kfree).

Add call to kobject_put() in the error path of call to
kobject_init_and_add().

Cc: stable@vger.kernel.org # v4.4+
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Tobin C. Harding <tobin@kernel.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index f79e477a378e7836bb3ad9739861cf0428afd1dc..9bcb3570750eec1f0418b22e6ccb65b0a9f461a2 100644 (file)
@@ -3882,8 +3882,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
                                    info->space_info_kobj, "%s",
                                    alloc_name(space_info->flags));
        if (ret) {
-               percpu_counter_destroy(&space_info->total_bytes_pinned);
-               kfree(space_info);
+               kobject_put(&space_info->kobj);
                return ret;
        }