LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Tobin C. Harding" <tobin@kernel.org>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>
Cc: "Tobin C. Harding" <tobin@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] fs: btrfs: Fix error path kobject memory leak
Date: Mon, 13 May 2019 13:39:11 +1000 [thread overview]
Message-ID: <20190513033912.3436-2-tobin@kernel.org> (raw)
In-Reply-To: <20190513033912.3436-1-tobin@kernel.org>
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.
Add call to kobject_put() in the error path of call to
kobject_init_and_add().
Signed-off-by: Tobin C. Harding <tobin@kernel.org>
---
fs/btrfs/extent-tree.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index c5880329ae37..5e40c8f1e97a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3981,8 +3981,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;
}
--
2.21.0
next prev parent reply other threads:[~2019-05-13 3:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 3:39 [PATCH 0/2] Fix kobject error path memleaks Tobin C. Harding
2019-05-13 3:39 ` Tobin C. Harding [this message]
2019-05-13 5:59 ` [PATCH 1/2] fs: btrfs: Fix error path kobject memory leak Nikolay Borisov
2019-05-13 7:11 ` Greg Kroah-Hartman
2019-05-13 3:39 ` [PATCH 2/2] fs: btrfs: Don't leak memory when failing add fsid Tobin C. Harding
2019-05-13 6:04 ` Nikolay Borisov
2019-05-13 10:57 ` Tobin C. Harding
2019-05-13 7:12 ` Greg Kroah-Hartman
2019-05-13 17:47 ` [PATCH 0/2] Fix kobject error path memleaks David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190513033912.3436-2-tobin@kernel.org \
--to=tobin@kernel.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--subject='Re: [PATCH 1/2] fs: btrfs: Fix error path kobject memory leak' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).