[PATCH] remote: Fix memory leak on error path when deserializing bulk stats

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

 



The 'elem' variable along with the domain object would be leaked when
taking the error path.

Found by coverity.
---
 src/remote/remote_driver.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index fda27f7..8bc4baa 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7730,7 +7730,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
     size_t i;
     remote_connect_get_all_domain_stats_args args;
     remote_connect_get_all_domain_stats_ret ret;
-
+    virDomainStatsRecordPtr elem = NULL;
     virDomainStatsRecordPtr *tmpret = NULL;

     if (ndoms) {
@@ -7769,7 +7769,6 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
         goto cleanup;

     for (i = 0; i < ret.retStats.retStats_len; i++) {
-        virDomainStatsRecordPtr elem;
         remote_domain_stats_record *rec = ret.retStats.retStats_val + i;

         if (VIR_ALLOC(elem) < 0)
@@ -7786,6 +7785,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
             goto cleanup;

         tmpret[i] = elem;
+        elem = NULL;
     }

     *retStats = tmpret;
@@ -7793,6 +7793,10 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
     rv = ret.retStats.retStats_len;

  cleanup:
+    if (elem) {
+        virObjectUnref(elem->dom);
+        VIR_FREE(elem);
+    }
     virDomainStatsRecordListFree(tmpret);
     xdr_free((xdrproc_t)xdr_remote_connect_get_all_domain_stats_ret,
              (char *) &ret);
-- 
2.0.2

--
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]