History

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>

Dave Jones committed 12 years ago

Commit 54b6a731 parent 9a417071 file · +15 −14Browse files

Unified · Split

mm/slub.c+15−14
@@ -5214,25 +5214,19 @@ static int sysfs_slab_add(struct kmem_cache *s) · 5213 unmodified lines
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) · 2 unmodified lines
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)