libvirt/SOURCES/libvirt-qemu-Fix-leak-in-qemuProcessInitCpuAffinity.patch
2021-09-10 11:57:18 +00:00

66 lines
2.3 KiB
Diff

From 4c58428a2aebd952f7412ec1f4afa3045a09dff7 Mon Sep 17 00:00:00 2001
Message-Id: <4c58428a2aebd952f7412ec1f4afa3045a09dff7@dist-git>
From: Andrea Bolognani <abologna@redhat.com>
Date: Tue, 11 Jun 2019 10:55:04 +0200
Subject: [PATCH] qemu: Fix leak in qemuProcessInitCpuAffinity()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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>
(cherry picked from commit 2f2254c7f4e5bff52ea62a77831230bebc076bab)
https://bugzilla.redhat.com/show_bug.cgi?id=1716908
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Message-Id: <20190611085506.12564-5-abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/qemu/qemu_process.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index a3b71354e1..0b2b7964e1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2357,8 +2357,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;
@@ -2393,11 +2392,11 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0)
goto cleanup;
} else if (vm->def->cputune.emulatorpin) {
- cpumapToSet = vm->def->cputune.emulatorpin;
- } else {
- if (qemuProcessGetAllCpuAffinity(&hostcpumap) < 0)
+ if (virBitmapCopy(cpumapToSet, vm->def->cputune.emulatorpin) < 0)
+ goto cleanup;
+ } else {
+ if (qemuProcessGetAllCpuAffinity(&cpumapToSet) < 0)
goto cleanup;
- cpumapToSet = hostcpumap;
}
if (cpumapToSet &&
--
2.22.0