[PATCH 2/2] coverity: fd and memory leak in nodeinfo.c

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

 



---
 src/nodeinfo.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index e842474..012f0f8 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -626,32 +626,31 @@ 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,
                              _("cannot open %s"), CPUINFO_PATH);
-        return -1;
+        return ret;
     }
 
     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;
 
-    return ret;
+    cleanup:
+        VIR_FREE(sysfs_cpuinfo);
+        VIR_FORCE_FCLOSE(cpuinfo);
+        return ret;
     }
 #else
     /* XXX Solaris will need an impl later if they port QEMU driver */
-- 
1.7.7.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]