]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: Don't leak @parent in virCgroupEnableMissingControllers()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 3 Feb 2021 19:17:15 +0000 (20:17 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 4 Feb 2021 08:08:16 +0000 (09:08 +0100)
A memory leak was identified in
virCgroupEnableMissingControllers():

==11680==    at 0x483EAE5: calloc (vg_replace_malloc.c:760)
==11680==    by 0x4E51780: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6701.0)
==11680==    by 0x4908618: virCgroupNew (vircgroup.c:701)
==11680==    by 0x49096F4: virCgroupEnableMissingControllers (vircgroup.c:1146)
==11680==    by 0x4909B17: virCgroupNewMachineSystemd (vircgroup.c:1228)
==11680==    by 0x4909E94: virCgroupNewMachine (vircgroup.c:1313)
==11680==    by 0x1694FDBC: qemuInitCgroup (qemu_cgroup.c:946)
==11680==    by 0x1695046B: qemuSetupCgroup (qemu_cgroup.c:1083)
==11680==    by 0x16A60126: qemuProcessLaunch (qemu_process.c:7077)
==11680==    by 0x16A61504: qemuProcessStart (qemu_process.c:7384)
==11680==    by 0x169B84C2: qemuDomainObjStart (qemu_driver.c:6590)
==11680==    by 0x169B8776: qemuDomainCreateWithFlags (qemu_driver.c:6641)

What happens is that new virCgroup is created and stored into
@parent. Then, if @tokens is not empty the for() loop is entered
into where another virCgroup is created and @parent is replaced
with this new virCgroup. But nothing freed the old @parent.

Fixes: 77291414c7a8745cf4d2b06d3c38d269cfbcfe32
Reported-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroup.c

index 15071d8b1b0e4af206145337f7d8649775c4697a..9fb1b45a8f3e6f788f9dc014c62b5aeb1c014482 100644 (file)
@@ -1159,6 +1159,7 @@ virCgroupEnableMissingControllers(char *path,
         if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0)
             return -1;
 
+        virCgroupFree(parent);
         parent = g_steal_pointer(&tmp);
     }