]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Unregister the connection close notifier upon termination
authorViktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Tue, 26 Mar 2013 09:54:55 +0000 (10:54 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 5 Apr 2013 08:36:03 +0000 (10:36 +0200)
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@linux.vnet.ibm.com>
tools/virsh.c

index 7ff12ec24f346aca4b346c00520927a8ccbdd8b5..d6c0e8cd2d4ba7d1900db7c8676052a35c8f0945 100644 (file)
@@ -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, "%s", _("One or more references were leaked after "
+                                  "disconnect from the hypervisor"));
     }
 
     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, "%s", _("One or more references were leaked after "
+                                  "disconnect from the hypervisor"));
     }
     virResetLastError();