[glib: 2/3] gdbusnamewatching: Check cancellation of a watch before calling back



commit 73a33e50197fe4b4c87b6f22977196e9b31da523
Author: Philip Withnall <withnall endlessm com>
Date:   Mon Jan 20 19:17:13 2020 +0000

    gdbusnamewatching: Check cancellation of a watch before calling back
    
    It’s possible for `g_bus_unwatch_name()` to be called after a
    name-appeared or name-vanished handler has been scheduled to be called
    in another thread, but before that callback is actually invoked. If so,
    the subscribing thread will receive a callback after it’s called
    `g_bus_unwatch_name()`, which is unexpected and could cause bugs.
    
    Double-check `client->cancelled` in the target thread before actually
    invoking the callback.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Fixes: #604

 gio/gdbusnamewatching.c | 5 +++++
 1 file changed, 5 insertions(+)
---
diff --git a/gio/gdbusnamewatching.c b/gio/gdbusnamewatching.c
index 7b850c0af..c103bb484 100644
--- a/gio/gdbusnamewatching.c
+++ b/gio/gdbusnamewatching.c
@@ -148,6 +148,11 @@ call_handler_data_free (CallHandlerData *data)
 static void
 actually_do_call (Client *client, GDBusConnection *connection, const gchar *name_owner, CallType call_type)
 {
+  /* The client might have been cancelled (g_bus_unwatch_name()) while we were
+   * sitting in the #GMainContext dispatch queue. */
+  if (client->cancelled)
+    return;
+
   switch (call_type)
     {
     case CALL_TYPE_NAME_APPEARED:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]