]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
gunit/006: fix ASan leak by calling cgroup_free()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 27 Feb 2026 08:43:12 +0000 (14:13 +0530)
committerKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 10 Mar 2026 16:38:04 +0000 (22:08 +0530)
CgroupGetCgroup1 tripped LeakSanitizer because the test freed the
top-level struct cgroup with free(), leaving the controllers and control
values allocated by cgroup_get_cgroup() on the heap:

Direct leak of 4240 byte(s) in 5 object(s) allocated from:
    #0 0x... in calloc
    #1 cgroup_add_controller (<source>/libcgroup/src/wrapper.c:79)
    #2 cgroup_get_cgroup (<source>/libcgroup/src/api.c:3973)

Replacing both free(cgrp) calls with cgroup_free(&cgrp) mirrors the
expected teardown path, unwinds the nested allocations, and clears
the ASan report without changing the test assertions.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tests/gunit/006-cgroup_get_cgroup.cpp

index e1ff67ca0a732f3af7c406e905e5d3cc643bdef2..ac934065fda757143194f5fac92f272c1eb5c30c 100644 (file)
@@ -227,7 +227,7 @@ TEST_F(CgroupGetCgroupTest, CgroupGetCgroup1)
        ASSERT_EQ(cgrp_vec, test_vec);
 
        if (cgrp)
-               free(cgrp);
+               cgroup_free(&cgrp);
 }
 
 /*
@@ -251,5 +251,5 @@ TEST_F(CgroupGetCgroupTest, CgroupGetCgroup_NoTasksFile)
        ASSERT_EQ(ret, ECGOTHER);
 
        if (cgrp)
-               free(cgrp);
+               cgroup_free(&cgrp);
 }