[PATCH 2/6] events: Add virObjectEventCallbackFree

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

 



---
 src/conf/object_event.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/conf/object_event.c b/src/conf/object_event.c
index 95bf3e6..1b5a4d0 100644
--- a/src/conf/object_event.c
+++ b/src/conf/object_event.c
@@ -126,6 +126,22 @@ virObjectEventDispose(void *obj)
 }
 
 /**
+ * virObjectEventCallbackFree:
+ * @list: event callback to free
+ *
+ * Free the memory in the domain event callback
+ */
+static void
+virObjectEventCallbackFree(virObjectEventCallbackPtr cb)
+{
+    if (!cb)
+        return;
+
+    virObjectUnref(cb->conn);
+    VIR_FREE(cb);
+}
+
+/**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
  *
@@ -230,8 +246,7 @@ virObjectEventCallbackListRemoveID(virConnectPtr conn,
 
             if (cb->freecb)
                 (*cb->freecb)(cb->opaque);
-            virObjectUnref(cb->conn);
-            VIR_FREE(cb);
+            virObjectEventCallbackFree(cb);
             VIR_DELETE_ELEMENT(cbList->callbacks, i, cbList->count);
             return ret;
         }
@@ -280,8 +295,7 @@ virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList)
             virFreeCallback freecb = cbList->callbacks[n]->freecb;
             if (freecb)
                 (*freecb)(cbList->callbacks[n]->opaque);
-            virObjectUnref(cbList->callbacks[n]->conn);
-            VIR_FREE(cbList->callbacks[n]);
+            virObjectEventCallbackFree(cbList->callbacks[n]);
 
             VIR_DELETE_ELEMENT(cbList->callbacks, n, cbList->count);
             n--;
@@ -441,9 +455,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn,
     }
 
  cleanup:
-    if (event)
-        virObjectUnref(event->conn);
-    VIR_FREE(event);
+    virObjectEventCallbackFree(event);
     return ret;
 }
 
-- 
2.7.4

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