[PATCH] mm/slub: fix kobject leak in sysfs_slab_add error path
From: Hongling Zeng
Date: Mon Jul 13 2026 - 01:59:01 EST
When kobject_init_and_add() fails in sysfs_slab_add(), the kobject
is not properly cleaned up, causing a memory leak.
According to the kobject API documentation, when kobject_init_and_add()
returns an error, the caller must call kobject_put() to properly clean
up the memory associated with the object. The current code only frees
the 'name' string but forgets to release the kobject reference.
Fix this by calling kobject_put() before jumping to the error label.
Fixes: 54b6a731025f ("slub: fix leak of 'name' in sysfs_slab_add")
Signed-off-by: Hongling Zeng <zenghongling@xxxxxxxxxx>
---
mm/slub.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index 9ec774dc7009..fec2cd08d129 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -9690,8 +9690,10 @@ 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)
+ if (err) {
+ kobject_put(&s->kobj);
goto out;
+ }
if (!unmergeable) {
/* Setup first alias */
--
2.25.1