]> xenbits.xensource.com Git - libvirt.git/commitdiff
Clean timer in virObjectEventStateFlush
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 11 Oct 2016 11:44:21 +0000 (13:44 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 12 Oct 2016 10:54:47 +0000 (12:54 +0200)
If the last event callback is unregistered while the event loop is
dispatching, it is only marked as deleted, but not removed.  The number
of callbacks is more than zero in that case, so the timer is not
removed.  Because it can be removed in this function now (but also
accessed afterwards so that we set 'isDispatching = false' and have it
locked), we need to temporarily increase the reference counter of the
state for the duration of this function.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/object_event.c

index 8f2c2d0f2083a0eb2561e4493e04738db21fe438..e5f942f0cca932bf62ae95d8257c53a2839b1c96 100644 (file)
@@ -807,6 +807,9 @@ virObjectEventStateFlush(virObjectEventStatePtr state)
 {
     virObjectEventQueue tempQueue;
 
+    /* We need to lock as well as ref due to the fact that we might
+     * unref the state we're working on in this very function */
+    virObjectRef(state);
     virObjectLock(state);
     state->isDispatching = true;
 
@@ -826,8 +829,13 @@ virObjectEventStateFlush(virObjectEventStatePtr state)
     /* Purge any deleted callbacks */
     virObjectEventCallbackListPurgeMarked(state->callbacks);
 
+    /* If we purged all callbacks, we need to remove the timeout as
+     * well like virObjectEventStateDeregisterID() would do. */
+    virObjectEventStateCleanupTimer(state, true);
+
     state->isDispatching = false;
     virObjectUnlock(state);
+    virObjectUnref(state);
 }