Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: alloc_fn: Calling allocation
function "fopen".
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: var_assign: Assigning:
"cpuinfo" = storage returned from "fopen("/proc/cpuinfo",
"r")".
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:638: leaked_storage: Variable
"cpuinfo" going out of scope leaks the storage it points to.
---
src/nodeinfo.c | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index e842474..56b9f54 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -626,8 +626,8 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr
nodeinfo) {
#ifdef __linux__
{
- int ret;
- char *sysfs_cpuinfo;
+ int ret = -1;
+ char *sysfs_cpuinfo = NULL;
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
if (!cpuinfo) {
virReportSystemError(errno,
@@ -637,20 +637,19 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr
nodeinfo) {
if (virAsprintf(&sysfs_cpuinfo, CPU_SYS_PATH) < 0) {
virReportOOMError();
- return -1;
+ goto cleanup;
}
ret = linuxNodeInfoCPUPopulate(cpuinfo, sysfs_cpuinfo, nodeinfo);
- VIR_FORCE_FCLOSE(cpuinfo);
- if (ret < 0) {
- VIR_FREE(sysfs_cpuinfo);
- return -1;
- }
+ if (ret < 0)
+ goto cleanup;
- VIR_FREE(sysfs_cpuinfo);
/* Convert to KB. */
nodeinfo->memory = physmem_total () / 1024;
+cleanup:
+ VIR_FORCE_FCLOSE(cpuinfo);
+ VIR_FREE(sysfs_cpuinfo);
return ret;
}
#else
--
1.7.7.3