From 593269a2a5babef97708824c08988c5fb2c096d1 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 23 Jun 2016 11:40:53 -0400 Subject: [PATCH] events: Add virObjectEventCallbackFree --- 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 95bf3e6619..1b5a4d018f 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -125,6 +125,22 @@ virObjectEventDispose(void *obj) VIR_FREE(event->meta.name); } +/** + * 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; } -- GitLab