]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Fix memory leak in virResctrlMonitorGetStats
authorJohn Ferlan <jferlan@redhat.com>
Wed, 14 Nov 2018 19:01:06 +0000 (14:01 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 14 Nov 2018 19:01:06 +0000 (14:01 -0500)
Missed during review and surprisingly my run through Coverity also
didn't see this. I only noticed it when reading the code while fixing
the build breaker for commit 36780a86a.

With all those continues we would leak @stats.

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

index ef5c668921df7e86286753debfba46976a2d24c7..7aeca9d287988c3298569015c46b62db74a633fd 100644 (file)
@@ -2684,9 +2684,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
     while (virDirRead(dirp, &ent, datapath) > 0) {
         char *node_id = NULL;
 
-        if (VIR_ALLOC(stat) < 0)
-            goto cleanup;
-
         /* Looking for directory that contains resource utilization
          * information file. The directory name is arranged in format
          * "mon_<node_name>_<node_id>". For example, "mon_L3_00" and
@@ -2709,6 +2706,9 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
         if (!(node_id = STRSKIP(node_id, "_")))
             continue;
 
+        if (VIR_ALLOC(stat) < 0)
+            goto cleanup;
+
         /* The node ID number should be here, parsing it. */
         if (virStrToLong_uip(node_id, NULL, 0, &stat->id) < 0)
             goto cleanup;