[libvirt] [libvirt-glib PATCHv5 2/7] gobject: Plug 2 virConnect leaks

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Jul 7 14:17:32 UTC 2015


A virConnect reference is leaked in error cases. This patch moves the
unref after the label we jump to on errors, to avoid this leak.
---
 libvirt-gobject/libvirt-gobject-connection.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index e088427..02eef7b 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -748,7 +748,6 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
     if (priv->domains)
         g_hash_table_unref(priv->domains);
     priv->domains = doms;
-    virConnectClose(vconn);
     g_mutex_unlock(priv->lock);
 
     ret = TRUE;
@@ -759,6 +758,8 @@ cleanup:
             virDomainFree(domains[i]);
         free(domains);
     }
+    if (vconn != NULL)
+        virConnectClose(vconn);
     return ret;
 }
 
@@ -835,7 +836,6 @@ gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn,
     if (priv->pools)
         g_hash_table_unref(priv->pools);
     priv->pools = pools;
-    virConnectClose(vconn);
     g_mutex_unlock(priv->lock);
 
     ret = TRUE;
@@ -846,6 +846,8 @@ cleanup:
             virStoragePoolFree(vpools[i]);
         free(vpools);
     }
+    if (vconn != NULL)
+        virConnectClose(vconn);
     return ret;
 }
 
-- 
2.4.3




More information about the libvir-list mailing list