]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/cgroup: Fix error path leaks in test_percpu_basic
authorYu Miao <yumiao@kylinos.cn>
Wed, 13 May 2026 02:39:07 +0000 (10:39 +0800)
committerTejun Heo <tj@kernel.org>
Wed, 13 May 2026 18:40:52 +0000 (08:40 -1000)
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.

Fixes: 90631e1dea55 ("kselftests: cgroup: add perpcu memory accounting test")
Signed-off-by: Yu Miao <yumiao@kylinos.cn>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/testing/selftests/cgroup/test_kmem.c

index eeabd34bf083704c20da54942ddd00ec1dc63bc5..12f59925500bd43e849f7f41de4e997c53c38c7a 100644 (file)
@@ -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);
        }