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.
This commit is contained in:
Stefan Berger 2011-12-09 12:18:58 -05:00 committed by Stefan Berger
parent 3b0bb65dd4
commit b1d6d56ceb

View File

@ -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;