render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From c2f30fd3e2111d1645b83cbfecda655ec0b2d7dc Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <c2f30fd3e2111d1645b83cbfecda655ec0b2d7dc@dist-git>
9119d9
From: Peter Krempa <pkrempa@redhat.com>
9119d9
Date: Tue, 2 Sep 2014 15:38:31 +0200
9119d9
Subject: [PATCH] remote: Fix memory leak on error path when deserializing bulk
9119d9
 stats
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1136350
9119d9
9119d9
The 'elem' variable along with the domain object would be leaked when
9119d9
taking the error path.
9119d9
9119d9
Found by coverity.
9119d9
9119d9
(cherry picked from commit 137d0165cd8c5daccc00786f8de272b57e68ff84)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/remote/remote_driver.c | 8 ++++++--
9119d9
 1 file changed, 6 insertions(+), 2 deletions(-)
9119d9
9119d9
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
9119d9
index fda27f7..8bc4baa 100644
9119d9
--- a/src/remote/remote_driver.c
9119d9
+++ b/src/remote/remote_driver.c
9119d9
@@ -7730,7 +7730,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
9119d9
     size_t i;
9119d9
     remote_connect_get_all_domain_stats_args args;
9119d9
     remote_connect_get_all_domain_stats_ret ret;
9119d9
-
9119d9
+    virDomainStatsRecordPtr elem = NULL;
9119d9
     virDomainStatsRecordPtr *tmpret = NULL;
9119d9
 
9119d9
     if (ndoms) {
9119d9
@@ -7769,7 +7769,6 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
9119d9
         goto cleanup;
9119d9
 
9119d9
     for (i = 0; i < ret.retStats.retStats_len; i++) {
9119d9
-        virDomainStatsRecordPtr elem;
9119d9
         remote_domain_stats_record *rec = ret.retStats.retStats_val + i;
9119d9
 
9119d9
         if (VIR_ALLOC(elem) < 0)
9119d9
@@ -7786,6 +7785,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
9119d9
             goto cleanup;
9119d9
 
9119d9
         tmpret[i] = elem;
9119d9
+        elem = NULL;
9119d9
     }
9119d9
 
9119d9
     *retStats = tmpret;
9119d9
@@ -7793,6 +7793,10 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
9119d9
     rv = ret.retStats.retStats_len;
9119d9
 
9119d9
  cleanup:
9119d9
+    if (elem) {
9119d9
+        virObjectUnref(elem->dom);
9119d9
+        VIR_FREE(elem);
9119d9
+    }
9119d9
     virDomainStatsRecordListFree(tmpret);
9119d9
     xdr_free((xdrproc_t)xdr_remote_connect_get_all_domain_stats_ret,
9119d9
              (char *) &ret;;
9119d9
-- 
9119d9
2.1.0
9119d9