summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.vnet.ibm.com>2011-12-09 12:18:58 -0500
committerStefan Berger <stefanb@us.ibm.com>2011-12-09 12:18:58 -0500
commitb1d6d56cebdc50e3b20255f129193c725bc68417 (patch)
treeac0b1d520a36382ea1f9cd3db1df6e92f5197035
parent3b0bb65dd4c5e159956c44e99ae5dd24758e68be (diff)
downloadlibvirt-b1d6d56cebdc50e3b20255f129193c725bc68417.tar.gz
fix memory leak in src/nodeinfo.c
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.
-rw-r--r--src/nodeinfo.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 3b4ac5094a..75379183c3 100644
--- a/src/nodeinfo.c
+++ b/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 ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) {
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;