[virt-tools-list] [virt-viewer v2 10/13] events: don't hold events lock when dispatching free callbacks

Fabiano Fidêncio fidencio at redhat.com
Wed Jul 22 08:04:37 UTC 2015


The _event_timeout_remove and _event_handle_remove methods
were holding onto the global lock when invoking the free
callback. This is a violation of the libvirt events API
contract which requires free callbacks to be invoked in
a re-entrant safe context.

Based on commit dd17c3cc587c73a8c915238f9d9a3e200e89c93f from
libvirt-glib.
Original author: Daniel P. Berrange <berrange at redhat.com>

Related to: rhbz#1243228
---
 src/virt-viewer-events.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/virt-viewer-events.c b/src/virt-viewer-events.c
index 1655a70..f68791f 100644
--- a/src/virt-viewer-events.c
+++ b/src/virt-viewer-events.c
@@ -203,13 +203,11 @@ virt_viewer_events_cleanup_handle(gpointer user_data)
     g_debug("Cleanup of handle %p", data);
     g_return_val_if_fail(data != NULL, FALSE);
 
-    g_mutex_lock(eventlock);
-
     if (data->ff)
         (data->ff)(data->opaque);
 
+    g_mutex_lock(eventlock);
     g_ptr_array_remove_fast(handles, data);
-
     g_mutex_unlock(eventlock);
 
     return FALSE;
@@ -382,13 +380,11 @@ virt_viewer_events_cleanup_timeout(gpointer user_data)
     g_debug("Cleanup of timeout %p", data);
     g_return_val_if_fail(data != NULL, FALSE);
 
-    g_mutex_lock(eventlock);
-
     if (data->ff)
         (data->ff)(data->opaque);
 
+    g_mutex_lock(eventlock);
     g_ptr_array_remove_fast(timeouts, data);
-
     g_mutex_unlock(eventlock);
 
     return FALSE;
-- 
2.4.4




More information about the virt-tools-list mailing list