linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* slub: fix leak of 'name' in sysfs_slab_add
@ 2014-03-06 21:11 Dave Jones
  2014-03-07  6:18 ` Vladimir Davydov
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Jones @ 2014-03-06 21:11 UTC (permalink / raw)
  To: Linux Kernel; +Cc: linux-mm, cl, penberg

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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-07 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-06 21:11 slub: fix leak of 'name' in sysfs_slab_add Dave Jones
2014-03-07  6:18 ` Vladimir Davydov
2014-03-07 15:32   ` Dave Jones
2014-03-07 17:14     ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox