]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Resource some resource leaks in virsysinfo code
authorJohn Ferlan <jferlan@redhat.com>
Tue, 7 Mar 2017 11:33:38 +0000 (06:33 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 7 Mar 2017 18:25:03 +0000 (13:25 -0500)
Calls to virFileReadAll after a VIR_ALLOC that return NULL all show
a memory leak since 'ret' isn't virSysinfoDefFree'd and normal path
"return ret" doesn't free outbuf.

Reported by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/util/virsysinfo.c

index 7b54bda12087e111a51a58a1ed18cef91492dd82..14c17a897db3c4050c45aff6d81fb5b30104ce11 100644 (file)
@@ -270,7 +270,7 @@ virSysinfoReadPPC(void)
     if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to open %s"), CPUINFO);
-        return NULL;
+        goto no_memory;
     }
 
     ret->nprocessor = 0;
@@ -281,10 +281,12 @@ virSysinfoReadPPC(void)
     if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0)
         goto no_memory;
 
+    VIR_FREE(outbuf);
     return ret;
 
  no_memory:
     VIR_FREE(outbuf);
+    virSysinfoDefFree(ret);
     return NULL;
 }
 
@@ -402,7 +404,7 @@ virSysinfoReadARM(void)
     if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to open %s"), CPUINFO);
-        return NULL;
+        goto no_memory;
     }
 
     ret->nprocessor = 0;
@@ -413,10 +415,12 @@ virSysinfoReadARM(void)
     if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0)
         goto no_memory;
 
+    VIR_FREE(outbuf);
     return ret;
 
  no_memory:
     VIR_FREE(outbuf);
+    virSysinfoDefFree(ret);
     return NULL;
 }
 
@@ -539,7 +543,7 @@ virSysinfoReadS390(void)
     if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to open %s"), CPUINFO);
-        return NULL;
+        goto no_memory;
     }
 
     ret->nprocessor = 0;
@@ -554,12 +558,13 @@ virSysinfoReadS390(void)
     if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to open %s"), SYSINFO);
-        return NULL;
+        goto no_memory;
     }
 
     if (virSysinfoParseS390System(outbuf, &ret->system) < 0)
         goto no_memory;
 
+    VIR_FREE(outbuf);
     return ret;
 
  no_memory: