[PATCH] Fix a memory leak in virCgroupGetPercpuStats

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 e65617a..6957e81 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 a455a81..cc1825b 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;
 }
 
-- 
2.0.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]