Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/slub: fix kobject leak in sysfs_slab_add error path
@ 2026-07-13  5:58 Hongling Zeng
  2026-07-13  6:07 ` Harry Yoo
  0 siblings, 1 reply; 5+ messages in thread
From: Hongling Zeng @ 2026-07-13  5:58 UTC (permalink / raw)
  To: vbabka, harry, akpm, hao.li, cl, rientjes, roman.gushchin,
	vdavydov.dev, davej
  Cc: linux-mm, linux-kernel, zhongling0719, Hongling Zeng

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@kylinos.cn>
---
 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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-13  7:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13  5:58 [PATCH] mm/slub: fix kobject leak in sysfs_slab_add error path Hongling Zeng
2026-07-13  6:07 ` Harry Yoo
2026-07-13  6:14   ` Hongling Zeng
2026-07-13  6:27     ` Harry Yoo
2026-07-13  7:09       ` Hongling Zeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox