From 7175699cbbd4ac2acadff0465430639d255c5efa Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 13 Apr 2012 10:53:17 +0200 Subject: [PATCH] qemu: Fix mem leak in qemuProcessInitCpuAffinity If placement mode is AUTO, on some return paths char *cpumap or char *nodeset are leaked. (cherry picked from commit 354e6d4ed0b71cc90084faea32c360ce86a85b42) --- src/qemu/qemu_process.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 481b4f3db0..828b2a4347 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1796,6 +1796,7 @@ static int qemuProcessInitCpuAffinity(struct qemud_driver *driver, virDomainObjPtr vm) { + int ret = -1; int i, hostcpus, maxcpu = QEMUD_CPUMASK_LEN; virNodeInfo nodeinfo; unsigned char *cpumap; @@ -1824,19 +1825,21 @@ qemuProcessInitCpuAffinity(struct qemud_driver *driver, nodeset = qemuGetNumadAdvice(vm->def); if (!nodeset) - return -1; + goto cleanup; if (VIR_ALLOC_N(tmp_cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) { virReportOOMError(); - return -1; + VIR_FREE(nodeset); + goto cleanup; } if (virDomainCpuSetParse(nodeset, 0, tmp_cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) { VIR_FREE(tmp_cpumask); VIR_FREE(nodeset); - return -1; + goto cleanup; } + VIR_FREE(nodeset); for (i = 0; i < maxcpu && i < VIR_DOMAIN_CPUMASK_LEN; i++) { if (tmp_cpumask[i]) @@ -1849,7 +1852,6 @@ qemuProcessInitCpuAffinity(struct qemud_driver *driver, VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } - VIR_FREE(nodeset); } else { if (vm->def->cpumask) { /* XXX why don't we keep 'cpumask' in the libvirt cpumap @@ -1872,13 +1874,14 @@ qemuProcessInitCpuAffinity(struct qemud_driver *driver, * running at this point */ if (virProcessInfoSetAffinity(0, /* Self */ - cpumap, cpumaplen, maxcpu) < 0) { - VIR_FREE(cpumap); - return -1; - } - VIR_FREE(cpumap); + cpumap, cpumaplen, maxcpu) < 0) + goto cleanup; - return 0; + ret = 0; + +cleanup: + VIR_FREE(cpumap); + return ret; } /* set link states to down on interfaces at qemu start */