From: Tobin C. Harding <tobin@kernel.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] gfs2: Fix error path kobject memory leak
Date: Mon, 13 May 2019 13:32:13 +1000 [thread overview]
Message-ID: <20190513033213.2468-1-tobin@kernel.org> (raw)
If a call to kobject_init_and_add() fails we must call kobject_put()
otherwise we leak memory.
Function always calls kobject_init_and_add() which always calls
kobject_init().
It is safe to leave object destruction up to the kobject release
function and never free it manually.
Remove call to kfree() and always call kobject_put() in the error path.
Signed-off-by: Tobin C. Harding <tobin@kernel.org>
---
Is it ok to send patches during the merge window?
Applies on top of Linus' mainline tag: v5.1
Happy to rebase if there are conflicts.
thanks,
Tobin.
fs/gfs2/sys.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 1787d295834e..98586b139386 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
if (error)
goto fail_reg;
- sysfs_frees_sdp = 1; /* Freeing sdp is now done by sysfs calling
- function gfs2_sbd_release. */
error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
if (error)
goto fail_reg;
@@ -687,10 +685,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
fail_reg:
free_percpu(sdp->sd_lkstats);
fs_err(sdp, "error %d adding sysfs files\n", error);
- if (sysfs_frees_sdp)
- kobject_put(&sdp->sd_kobj);
- else
- kfree(sdp);
+ kobject_put(&sdp->sd_kobj);
sb->s_fs_info = NULL;
return error;
}
--
2.21.0
WARNING: multiple messages have this Message-ID (diff)
From: "Tobin C. Harding" <tobin@kernel.org>
To: Bob Peterson <rpeterso@redhat.com>,
Andreas Gruenbacher <agruenba@redhat.com>
Cc: "Tobin C. Harding" <tobin@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
cluster-devel@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH] gfs2: Fix error path kobject memory leak
Date: Mon, 13 May 2019 13:32:13 +1000 [thread overview]
Message-ID: <20190513033213.2468-1-tobin@kernel.org> (raw)
If a call to kobject_init_and_add() fails we must call kobject_put()
otherwise we leak memory.
Function always calls kobject_init_and_add() which always calls
kobject_init().
It is safe to leave object destruction up to the kobject release
function and never free it manually.
Remove call to kfree() and always call kobject_put() in the error path.
Signed-off-by: Tobin C. Harding <tobin@kernel.org>
---
Is it ok to send patches during the merge window?
Applies on top of Linus' mainline tag: v5.1
Happy to rebase if there are conflicts.
thanks,
Tobin.
fs/gfs2/sys.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 1787d295834e..98586b139386 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
if (error)
goto fail_reg;
- sysfs_frees_sdp = 1; /* Freeing sdp is now done by sysfs calling
- function gfs2_sbd_release. */
error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
if (error)
goto fail_reg;
@@ -687,10 +685,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
fail_reg:
free_percpu(sdp->sd_lkstats);
fs_err(sdp, "error %d adding sysfs files\n", error);
- if (sysfs_frees_sdp)
- kobject_put(&sdp->sd_kobj);
- else
- kfree(sdp);
+ kobject_put(&sdp->sd_kobj);
sb->s_fs_info = NULL;
return error;
}
--
2.21.0
next reply other threads:[~2019-05-13 3:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 3:32 Tobin C. Harding [this message]
2019-05-13 3:32 ` [PATCH] gfs2: Fix error path kobject memory leak Tobin C. Harding
2019-05-13 7:14 ` [Cluster-devel] " Greg Kroah-Hartman
2019-05-13 7:14 ` Greg Kroah-Hartman
2019-05-13 10:39 ` [Cluster-devel] " Tobin C. Harding
2019-05-13 10:39 ` Tobin C. Harding
2019-05-13 16:41 ` [Cluster-devel] " Andreas Gruenbacher
2019-05-13 16:41 ` Andreas Gruenbacher
2019-05-13 21:40 ` [Cluster-devel] " Tobin C. Harding
2019-05-13 21:40 ` Tobin C. Harding
-- strict thread matches above, loose matches on Subject: below --
2019-05-13 19:59 [Cluster-devel] " Andreas Gruenbacher
2019-05-13 22:27 ` Linus Torvalds
2019-05-13 22:37 ` Andreas Gruenbacher
2019-05-13 22:47 ` Linus Torvalds
2019-05-13 22:57 ` Andreas Gruenbacher
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=20190513033213.2468-1-tobin@kernel.org \
--to=tobin@kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.