]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix a memory leak in cgroup_init()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Sat, 19 Mar 2022 06:41:50 +0000 (12:11 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 21 Mar 2022 14:17:33 +0000 (08:17 -0600)
temp_ent is not free'ed in the error path if cgroup_process_v1_mnt() or
cgroup_process_v2_mnt() fails.  Move the free'ing of temp_ent to error
path.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 108417cbaf4d3f6807207c38c8197e49f9039577..89b59ea7911a6e12fcb216ea8aa668989d6fc408 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1416,8 +1416,6 @@ int cgroup_init(void)
                }
        }
 
-       free(temp_ent);
-
        if (!found_mnt) {
                cg_mount_table[0].name[0] = '\0';
                ret = ECGROUPNOTMOUNTED;
@@ -1436,6 +1434,9 @@ unlock_exit:
        if (proc_mount)
                fclose(proc_mount);
 
+       if (temp_ent)
+               free(temp_ent);
+
        for (i = 0; controllers[i]; i++) {
                free(controllers[i]);
                controllers[i] = NULL;