[PATCHv2 2/4] virsh: Unregister the connection close notifier upon termination

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

 



From: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>

Before closing the connection we unregister the close callback
to prevent a reference leak.

Further, the messages on virConnectClose != 0 are a bit more specific
now.

Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>
---
 tools/virsh.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 7ff12ec..6588470 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -321,9 +321,18 @@ vshReconnect(vshControl *ctl)
 {
     bool connected = false;

-    if (ctl->conn != NULL) {
+    if (ctl->conn) {
+        int ret;
+
         connected = true;
-        virConnectClose(ctl->conn);
+
+        virConnectUnregisterCloseCallback(ctl->conn, vshCatchDisconnect);
+        ret = virConnectClose(ctl->conn);
+        if (ret < 0)
+            vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
+        else if (ret > 0)
+            vshError(ctl, _("Leaked %d reference(s) after disconnect "
+                            "from the hypervisor"), ret);
     }

     ctl->conn = virConnectOpenAuth(ctl->name,
@@ -2660,9 +2669,13 @@ vshDeinit(vshControl *ctl)
     VIR_FREE(ctl->name);
     if (ctl->conn) {
         int ret;
-        if ((ret = virConnectClose(ctl->conn)) != 0) {
-            vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
-        }
+        virConnectUnregisterCloseCallback(ctl->conn, vshCatchDisconnect);
+        ret = virConnectClose(ctl->conn);
+        if (ret < 0)
+            vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
+        else if (ret > 0)
+            vshError(ctl, _("Leaked %d reference(s) after disconnect "
+                            "from the hypervisor"), ret);
     }
     virResetLastError();

-- 
1.8.1.5

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