]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix memory leak on non-writable settings
authorFelix Moessbauer <felix.moessbauer@siemens.com>
Wed, 16 Oct 2024 13:30:29 +0000 (15:30 +0200)
committerKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 21 Oct 2024 04:52:39 +0000 (10:22 +0530)
When hitting the path st_mode check, we might already have allocated a
path. In this case, the continue re-enters the loop without freeing the
path:

 653 bytes in 8 blocks are definitely lost in loss record
    at 0x484582F: realloc (vg_replace_malloc.c:1437)
    by 0x49023E1: __vasprintf_internal (vasprintf.c:79)
    by 0x48D5BD5: asprintf (asprintf.c:31)
    by 0x4B41722: cgroup_set_values_recursive (api.c:2414)
    by 0x4B4688A: _cgroup_create_cgroup (api.c:2999)
    by 0x4B47067: cgroup_create_cgroup (api.c:3062)
    by 0x4B47067: cgroup_create_cgroup (api.c:3028)

Fixes: 0e50142a1fe0 ("api.c: Don't fail a recursive write if value isn't dirty")
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
src/api.c

index 8c1809983a68d0cb43fd80a2e76152332793a229..f5cd24b2926da0a80ea56e42717aa71b87564ace 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -2427,8 +2427,11 @@ STATIC int cgroup_set_values_recursive(const char * const base,
                }
 
                /* 0200 == S_IWUSR */
-               if (!(path_stat.st_mode & 0200))
+               if (!(path_stat.st_mode & 0200)) {
+                       free(path);
+                       path = NULL;
                        continue;
+               }
 
                cgroup_dbg("setting %s to \"%s\", pathlen %d\n", path, cv->value, ret);