diff mbox

[2/6] events: Add virObjectEventCallbackFree

Message ID a9373e1a06935fba145baf68fbfd3e5a26823850.1466699232.git.crobinso@redhat.com
State Accepted
Commit 593269a2a5babef97708824c08988c5fb2c096d1
Headers show

Commit Message

Cole Robinson June 23, 2016, 4:27 p.m. UTC
---
 src/conf/object_event.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox

Patch

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;
 }