[libvirt] [PATCH] util: Fix memory leak in virResctrlMonitorGetStats

John Ferlan posted 1 patch 5 years, 5 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20181114190536.10652-1-jferlan@redhat.com
src/util/virresctrl.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[libvirt] [PATCH] util: Fix memory leak in virResctrlMonitorGetStats
Posted by John Ferlan 5 years, 5 months ago
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>
---
 Pushing under trivial rule.

 src/util/virresctrl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index ef5c668921..7aeca9d287 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -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;
-- 
2.17.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list