kobject_init_and_add() takes reference even when it fails. If this function returns an error in sysfs_slab_add(), kobject_put() should be called to properly clean up the memory associated with the object. This issue was found by a static analysis tool I am developing. Fixes: 26e4f2057516 ("slub: Fix possible format string bug.") Signed-off-by: Guangshuo Li --- mm/slub.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 2b2d33cc735c..9f0f03460b4d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -9492,7 +9492,7 @@ static int sysfs_slab_add(struct kmem_cache *s) s->kobj.kset = kset; err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name); if (err) - goto out; + goto out_put_kobj; err = sysfs_create_group(&s->kobj, &slab_attr_group); if (err) @@ -9506,6 +9506,9 @@ static int sysfs_slab_add(struct kmem_cache *s) if (!unmergeable) kfree(name); return err; +out_put_kobj: + kobject_put(&s->kobj); + goto out; out_del_kobj: kobject_del(&s->kobj); goto out; -- 2.43.0