]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Fix leak in qemuProcessInitCpuAffinity()
authorAndrea Bolognani <abologna@redhat.com>
Tue, 4 Jun 2019 12:36:21 +0000 (14:36 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Tue, 4 Jun 2019 13:53:51 +0000 (15:53 +0200)
In two out of three scenarios we are cleaning up properly after
ourselves, but commit 5f2212c062c7 has changed the remaining one
in a way that caused it to start leaking cpumapToSet.

Refactor the logic so that cpumapToSet is always a freshly
allocated bitmap that gets cleaned up automatically thanks to
VIR_AUTOPTR(); this also allows us to remove the hostcpumap
variable.

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_process.c

index d44076288e635ad0fbe0e5ec80ff05d07b10d693..7d48c959739596b1ab731285a8748bce43b0d06e 100644 (file)
@@ -2464,8 +2464,7 @@ static int
 qemuProcessInitCpuAffinity(virDomainObjPtr vm)
 {
     int ret = -1;
-    virBitmapPtr cpumapToSet = NULL;
-    VIR_AUTOPTR(virBitmap) hostcpumap = NULL;
+    VIR_AUTOPTR(virBitmap) cpumapToSet = NULL;
     virDomainNumatuneMemMode mem_mode;
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
@@ -2500,11 +2499,11 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
         if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0)
             goto cleanup;
     } else if (vm->def->cputune.emulatorpin) {
-        cpumapToSet = vm->def->cputune.emulatorpin;
+        if (virBitmapCopy(cpumapToSet, vm->def->cputune.emulatorpin) < 0)
+            goto cleanup;
     } else {
-        if (qemuProcessGetAllCpuAffinity(&hostcpumap) < 0)
+        if (qemuProcessGetAllCpuAffinity(&cpumapToSet) < 0)
             goto cleanup;
-        cpumapToSet = hostcpumap;
     }
 
     if (cpumapToSet &&