From 65aa3e3414262f1273d584cf46c7d279b2103e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 15 Jan 2013 15:43:08 +0100 Subject: [PATCH] conf: fix leak in virDomainVcpuPinAdd Fix the leak of vcpupin on failure to allocate cpumask and the leak of cpumask if we fail to expand vcpupin_list. --- src/conf/domain_conf.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 41e7282d27..88865b5c97 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11900,26 +11900,25 @@ int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list, /* No existing vcpupin matches vcpu, adding a new one */ - if (VIR_ALLOC(vcpupin) < 0) { - virReportOOMError(); - return -1; - } + if (VIR_ALLOC(vcpupin) < 0) + goto no_memory; + vcpupin->vcpuid = vcpu; vcpupin->cpumask = virBitmapNewData(cpumap, maplen); - if (!vcpupin->cpumask) { - virReportOOMError(); - return -1; - } + if (!vcpupin->cpumask) + goto no_memory; - if (VIR_REALLOC_N(*vcpupin_list, *nvcpupin + 1) < 0) { - virReportOOMError(); - VIR_FREE(vcpupin); - return -1; - } + if (VIR_REALLOC_N(*vcpupin_list, *nvcpupin + 1) < 0) + goto no_memory; (*vcpupin_list)[(*nvcpupin)++] = vcpupin; return 0; + +no_memory: + virReportOOMError(); + virDomainVcpuPinDefFree(vpcupin); + return -1; } int -- GitLab