[PATCH] fix memory leak in src/nodeinfo.c

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

 



Fix memory leak:

==27534== 24 bytes in 1 blocks are definitely lost in loss record 207 of 530
==27534==    at 0x4A05E46: malloc (vg_replace_malloc.c:195)
==27534==    by 0x38EC26EC37: vasprintf (in /lib64/libc-2.13.so)
==27534==    by 0x4E998E6: virVasprintf (util.c:1677)
==27534==    by 0x4E999F1: virAsprintf (util.c:1695)
==27534==    by 0x4F1EAAC: nodeGetInfo (nodeinfo.c:593)
==27534==    by 0x47948F: qemuCapsInitCPU (qemu_capabilities.c:855)
==27534==    by 0x4796B1: qemuCapsInit (qemu_capabilities.c:915)
==27534==    by 0x456550: qemuCreateCapabilities (qemu_driver.c:245)
==27534==    by 0x4578C4: qemudStartup (qemu_driver.c:580)
==27534==    by 0x4F20886: virStateInitialize (libvirt.c:852)
==27534==    by 0x420E55: daemonRunStateInit (libvirtd.c:1156)
==27534==    by 0x4E94C56: virThreadHelper (threads-pthread.c:157)

Mark this leaked variable as const char * when it is passed into another
function.

---
 src/nodeinfo.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Index: libvirt-iterator/src/nodeinfo.c
===================================================================
--- libvirt-iterator.orig/src/nodeinfo.c
+++ libvirt-iterator/src/nodeinfo.c
@@ -68,7 +68,7 @@

 /* NB, this is not static as we need to call it from the testsuite */
 int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
-                             char *sysfs_cpudir,
+                             const char *sysfs_cpudir,
                              virNodeInfoPtr nodeinfo);

 static int linuxNodeGetCPUStats(FILE *procstat,
@@ -199,7 +199,7 @@ static int parse_core(unsigned int cpu)
 }

 int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
-                             char *sysfs_cpudir,
+                             const char *sysfs_cpudir,
                              virNodeInfoPtr nodeinfo)
 {
     char line[1024];
@@ -597,9 +597,12 @@ int nodeGetInfo(virConnectPtr conn ATTRI

     ret = linuxNodeInfoCPUPopulate(cpuinfo, sysfs_cpuinfo, nodeinfo);
     VIR_FORCE_FCLOSE(cpuinfo);
-    if (ret < 0)
+    if (ret < 0) {
+        VIR_FREE(sysfs_cpuinfo);
         return -1;
+    }

+    VIR_FREE(sysfs_cpuinfo);
     /* Convert to KB. */
     nodeinfo->memory = physmem_total () / 1024;

--
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]