c313de
From 4c58428a2aebd952f7412ec1f4afa3045a09dff7 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <4c58428a2aebd952f7412ec1f4afa3045a09dff7@dist-git>
c313de
From: Andrea Bolognani <abologna@redhat.com>
c313de
Date: Tue, 11 Jun 2019 10:55:04 +0200
c313de
Subject: [PATCH] qemu: Fix leak in qemuProcessInitCpuAffinity()
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
In two out of three scenarios we are cleaning up properly after
c313de
ourselves, but commit 5f2212c062c7 has changed the remaining one
c313de
in a way that caused it to start leaking cpumapToSet.
c313de
c313de
Refactor the logic so that cpumapToSet is always a freshly
c313de
allocated bitmap that gets cleaned up automatically thanks to
c313de
VIR_AUTOPTR(); this also allows us to remove the hostcpumap
c313de
variable.
c313de
c313de
Reported-by: John Ferlan <jferlan@redhat.com>
c313de
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
(cherry picked from commit 2f2254c7f4e5bff52ea62a77831230bebc076bab)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1716908
c313de
c313de
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c313de
Message-Id: <20190611085506.12564-5-abologna@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/qemu/qemu_process.c | 11 +++++------
c313de
 1 file changed, 5 insertions(+), 6 deletions(-)
c313de
c313de
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
c313de
index a3b71354e1..0b2b7964e1 100644
c313de
--- a/src/qemu/qemu_process.c
c313de
+++ b/src/qemu/qemu_process.c
c313de
@@ -2357,8 +2357,7 @@ static int
c313de
 qemuProcessInitCpuAffinity(virDomainObjPtr vm)
c313de
 {
c313de
     int ret = -1;
c313de
-    virBitmapPtr cpumapToSet = NULL;
c313de
-    VIR_AUTOPTR(virBitmap) hostcpumap = NULL;
c313de
+    VIR_AUTOPTR(virBitmap) cpumapToSet = NULL;
c313de
     virDomainNumatuneMemMode mem_mode;
c313de
     qemuDomainObjPrivatePtr priv = vm->privateData;
c313de
 
c313de
@@ -2393,11 +2392,11 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
c313de
         if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0)
c313de
             goto cleanup;
c313de
     } else if (vm->def->cputune.emulatorpin) {
c313de
-        cpumapToSet = vm->def->cputune.emulatorpin;
c313de
-    } else {
c313de
-        if (qemuProcessGetAllCpuAffinity(&hostcpumap) < 0)
c313de
+        if (virBitmapCopy(cpumapToSet, vm->def->cputune.emulatorpin) < 0)
c313de
+            goto cleanup;
c313de
+    } else {
c313de
+        if (qemuProcessGetAllCpuAffinity(&cpumapToSet) < 0)
c313de
             goto cleanup;
c313de
-        cpumapToSet = hostcpumap;
c313de
     }
c313de
 
c313de
     if (cpumapToSet &&
c313de
-- 
c313de
2.22.0
c313de