From b54f48812d2a495674476533b45c5bcb6b2dad91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Mon, 26 Jan 2015 10:20:22 +0100 Subject: [PATCH] Fix a memory leak in virCgroupGetPercpuStats Coverity reports that my commit af1c98e introduced two memory leaks: the cpumap if ncpus == 0 in virCgroupGetPercpuStats and the params array in the test of the function. --- src/util/vircgroup.c | 6 ++++-- tests/vircgrouptest.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e65617a8a4..6957e81d54 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3061,8 +3061,10 @@ virCgroupGetPercpuStats(virCgroupPtr group, total_cpus = virBitmapSize(cpumap); - if (ncpus == 0) - return total_cpus; + if (ncpus == 0) { + rv = total_cpus; + goto cleanup; + } if (start_cpu >= total_cpus) { virReportError(VIR_ERR_INVALID_ARG, diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index a455a8101a..cc1825bb24 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -614,6 +614,7 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED) cleanup: virCgroupFree(&cgroup); + VIR_FREE(params); return ret; }