Skip to content

Commit 54b6a73

Browse files
Dave Jonestorvalds
authored andcommitted
slub: fix leak of 'name' in sysfs_slab_add
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. [vdavydov@parallels.com: free the name only if !unmergeable] Signed-off-by: Dave Jones <davej@fedoraproject.org> Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Cc: Pekka Enberg <penberg@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9a41707 commit 54b6a73

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

mm/slub.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,25 +5214,19 @@ static int sysfs_slab_add(struct kmem_cache *s)
52145214

52155215
s->kobj.kset = cache_kset(s);
52165216
err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
5217-
if (err) {
5218-
kobject_put(&s->kobj);
5219-
return err;
5220-
}
5217+
if (err)
5218+
goto out_put_kobj;
52215219

52225220
err = sysfs_create_group(&s->kobj, &slab_attr_group);
5223-
if (err) {
5224-
kobject_del(&s->kobj);
5225-
kobject_put(&s->kobj);
5226-
return err;
5227-
}
5221+
if (err)
5222+
goto out_del_kobj;
52285223

52295224
#ifdef CONFIG_MEMCG_KMEM
52305225
if (is_root_cache(s)) {
52315226
s->memcg_kset = kset_create_and_add("cgroup", NULL, &s->kobj);
52325227
if (!s->memcg_kset) {
5233-
kobject_del(&s->kobj);
5234-
kobject_put(&s->kobj);
5235-
return -ENOMEM;
5228+
err = -ENOMEM;
5229+
goto out_del_kobj;
52365230
}
52375231
}
52385232
#endif
@@ -5241,9 +5235,16 @@ static int sysfs_slab_add(struct kmem_cache *s)
52415235
if (!unmergeable) {
52425236
/* Setup first alias */
52435237
sysfs_slab_alias(s, s->name);
5244-
kfree(name);
52455238
}
5246-
return 0;
5239+
out:
5240+
if (!unmergeable)
5241+
kfree(name);
5242+
return err;
5243+
out_del_kobj:
5244+
kobject_del(&s->kobj);
5245+
out_put_kobj:
5246+
kobject_put(&s->kobj);
5247+
goto out;
52475248
}
52485249

52495250
static void sysfs_slab_remove(struct kmem_cache *s)

0 commit comments

Comments
 (0)