Timeout and watch deletion is done from an idle callback. However,
we cannot assume that all libvirt event calls (the callbacks passed
to virEventRegisterImpl) will be done from the mainloop thread. It's
thus possible that a libvirt event call will run a thread while
one of the idle deletion callbacks runs.
Given that the 'handles' and 'timeouts' arrays are shared among all
threads, we need to make sure we hold the 'eventlock' mutex before
modifying them.
---
libvirt-glib/libvirt-glib-event.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c
index c2eeb7a..587a59e 100644
--- a/libvirt-glib/libvirt-glib-event.c
+++ b/libvirt-glib/libvirt-glib-event.c
@@ -255,11 +255,15 @@ _event_handle_remove(gpointer data)
{
struct gvir_event_handle *h = data;
+ g_mutex_lock(eventlock);
+
if (h->ff)
(h->ff)(h->opaque);
g_ptr_array_remove_fast(handles, h);
+ g_mutex_unlock(eventlock);
+
return FALSE;
}
@@ -404,11 +408,15 @@ _event_timeout_remove(gpointer data)
{
struct gvir_event_timeout *t = data;
+ g_mutex_lock(eventlock);
+
if (t->ff)
(t->ff)(t->opaque);
g_ptr_array_remove_fast(timeouts, t);
+ g_mutex_unlock(eventlock);
+
return FALSE;
}
--
1.7.10.2