diff options
author | Tobin C. Harding <tobin@kernel.org> | 2019-05-12 23:39:11 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2019-05-16 08:31:01 -0400 |
commit | 450ff8348808a89cc27436771aa05c2b90c0eef1 (patch) | |
tree | f3b1626d7b2620b987f9d0f2f06783fdf228466b | |
parent | 72bd2323ec87722c115a5906bc6a1b31d11e8f54 (diff) |
btrfs: sysfs: Fix error path kobject memory leak
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>
-rw-r--r-- | fs/btrfs/extent-tree.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f79e477a378e..9bcb3570750e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3882,8 +3882,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) | |||
3882 | info->space_info_kobj, "%s", | 3882 | info->space_info_kobj, "%s", |
3883 | alloc_name(space_info->flags)); | 3883 | alloc_name(space_info->flags)); |
3884 | if (ret) { | 3884 | if (ret) { |
3885 | percpu_counter_destroy(&space_info->total_bytes_pinned); | 3885 | kobject_put(&space_info->kobj); |
3886 | kfree(space_info); | ||
3887 | return ret; | 3886 | return ret; |
3888 | } | 3887 | } |
3889 | 3888 | ||