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