slub: fix leak of 'name' in sysfs_slab_add

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx>

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@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]