From: Dave Jones <davej@redhat.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>
Cc: linux-mm@kvack.org, cl@linux-foundation.org, penberg@kernel.org
Subject: slub: fix leak of 'name' in sysfs_slab_add
Date: Thu, 6 Mar 2014 16:11:41 -0500 [thread overview]
Message-ID: <20140306211141.GA17009@redhat.com> (raw)
The failure paths of sysfs_slab_add don't release the allocation of 'name'
made by create_unique_id() a few lines above the context of the diff below.
Create a common exit path to make it more obvious what needs freeing.
Signed-off-by: Dave Jones <davej@fedoraproject.org>
diff --git a/mm/slub.c b/mm/slub.c
index 25f14ad8f817..b2181d2682ac 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5197,17 +5197,13 @@ static int sysfs_slab_add(struct kmem_cache *s)
s->kobj.kset = slab_kset;
err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
- if (err) {
- kobject_put(&s->kobj);
- return err;
- }
+ if (err)
+ goto err_out;
err = sysfs_create_group(&s->kobj, &slab_attr_group);
- if (err) {
- kobject_del(&s->kobj);
- kobject_put(&s->kobj);
- return err;
- }
+ if (err)
+ goto err_sysfs;
+
kobject_uevent(&s->kobj, KOBJ_ADD);
if (!unmergeable) {
/* Setup first alias */
@@ -5215,6 +5211,13 @@ static int sysfs_slab_add(struct kmem_cache *s)
kfree(name);
}
return 0;
+
+err_sysfs:
+ kobject_del(&s->kobj);
+err_out:
+ kobject_put(&s->kobj);
+ kfree(name);
+ return err;
}
static void sysfs_slab_remove(struct kmem_cache *s)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2014-03-06 21:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-06 21:11 Dave Jones [this message]
2014-03-07 6:18 ` Vladimir Davydov
2014-03-07 15:32 ` Dave Jones
2014-03-07 17:14 ` Christoph Lameter
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=20140306211141.GA17009@redhat.com \
--to=davej@redhat.com \
--cc=cl@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox