render / rpms / libvirt

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