Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] selftests/cgroup: Fix error path leaks in test_percpu_basic
@ 2026-05-13  2:39 Yu Miao
  2026-05-13 18:56 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Yu Miao @ 2026-05-13  2:39 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
	Tejun Heo, Michal Koutný, Shuah Khan
  Cc: Muchun Song, cgroups, linux-mm, linux-kselftest, linux-kernel,
	Yu Miao

When cg_name_indexed() returns NULL partway through the child creation
loop, the code returned -1 without running cleanup_children and cleanup.
That left the `parent` pathname allocation unreleased and did not remove
child cgroup directories already created under the parent. Fix by jumping
to cleanup_children instead of returning.

When cg_create() fails, `child` (the pathname from cg_name_indexed())
was not freed before cleanup_children. Fix by freeing `child` before
branching to cleanup_children.

Signed-off-by: Yu Miao <yumiao@kylinos.cn>
---
 tools/testing/selftests/cgroup/test_kmem.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
index eeabd34bf083..12f59925500b 100644
--- a/tools/testing/selftests/cgroup/test_kmem.c
+++ b/tools/testing/selftests/cgroup/test_kmem.c
@@ -368,11 +368,15 @@ static int test_percpu_basic(const char *root)
 
 	for (i = 0; i < 1000; i++) {
 		child = cg_name_indexed(parent, "child", i);
-		if (!child)
-			return -1;
+		if (!child) {
+			ret = -1;
+			goto cleanup_children;
+		}
 
-		if (cg_create(child))
+		if (cg_create(child)) {
+			free(child);
 			goto cleanup_children;
+		}
 
 		free(child);
 	}
-- 
2.43.0


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

* Re: [PATCH] selftests/cgroup: Fix error path leaks in test_percpu_basic
  2026-05-13  2:39 [PATCH] selftests/cgroup: Fix error path leaks in test_percpu_basic Yu Miao
@ 2026-05-13 18:56 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-05-13 18:56 UTC (permalink / raw)
  To: Yu Miao
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
	Michal Koutný, Shuah Khan, Muchun Song, cgroups, linux-mm,
	linux-kselftest, linux-kernel

Hello,

On Wed, May 13, 2026 at 10:39:07AM +0800, Yu Miao wrote:
> [PATCH] selftests/cgroup: Fix error path leaks in test_percpu_basic

Applied to cgroup/for-7.1-fixes with the following Fixes: tag added:

  Fixes: 90631e1dea55 ("kselftests: cgroup: add perpcu memory accounting test")

Thanks.

--
tejun

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

end of thread, other threads:[~2026-05-13 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13  2:39 [PATCH] selftests/cgroup: Fix error path leaks in test_percpu_basic Yu Miao
2026-05-13 18:56 ` Tejun Heo

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