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

[libvirt] [PATCH] Fix ref-counting for Xen driver event registration



# HG changeset patch
# User john levon sun com
# Date 1231958879 28800
# Node ID 46dc909bda5b20d11f08d1516f21c05f27b6648f
# Parent  1fca4b0dd4c6ab3c0030b4986de6fe5cb7c94631
Fix ref-counting for Xen driver event registration

Signed-off-by: John Levon <john levon sun com>

diff --git a/src/xen_unified.c b/src/xen_unified.c
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -1359,15 +1359,21 @@ xenUnifiedDomainEventRegister (virConnec
                                void *opaque,
                                void (*freefunc)(void *))
 {
+    int ret;
+
     GET_PRIVATE (conn);
     if (priv->xsWatch == -1) {
         xenUnifiedError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
         return -1;
     }
 
-    conn->refs++;
-    return virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks,
-                                         callback, opaque, freefunc);
+    ret = virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks,
+        callback, opaque, freefunc);
+
+    if (ret == 0)
+        conn->refs++;
+
+    return (ret);
 }
 
 static int
@@ -1382,8 +1388,10 @@ xenUnifiedDomainEventDeregister (virConn
     }
 
     ret = virDomainEventCallbackListRemove(conn, priv->domainEventCallbacks,
-                                            callback);
-    virUnrefConnect(conn);
+        callback);
+
+    if (ret == 0)
+        virUnrefConnect(conn);
     return ret;
 }
 


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