Fix a critical when processing deferred messages
authorGiovanni Campagna <gcampagna@src.gnome.org>
Thu, 13 Feb 2014 14:04:53 +0000 (15:04 +0100)
committerMike Gorse <mgorse@suse.com>
Mon, 17 Feb 2014 17:20:53 +0000 (11:20 -0600)
Due to GMainContext manipulations and reentrancy issues, it's
possible the source pointer is NULL inside the callback.
Let's avoid the critical warning by unreffing the source early
- it is kept alive by GMainContext anyway after the attach.

https://bugzilla.gnome.org/show_bug.cgi?id=724292

atspi/atspi-misc.c

index 28de86f..48dd063 100644 (file)
@@ -747,7 +747,6 @@ process_deferred_messages_callback (gpointer data)
   if (process_deferred_messages ())
     return G_SOURCE_CONTINUE;
 
-  g_source_unref (process_deferred_messages_source);
   process_deferred_messages_source = NULL;
   return G_SOURCE_REMOVE;
 }
@@ -769,6 +768,7 @@ defer_message (DBusConnection *connection, DBusMessage *message, void *user_data
     g_source_set_callback (process_deferred_messages_source,
                            process_deferred_messages_callback, NULL, NULL);
     g_source_attach (process_deferred_messages_source, atspi_main_context);
+    g_source_unref (process_deferred_messages_source);
   }
 
   return DBUS_HANDLER_RESULT_HANDLED;
@@ -1608,9 +1608,9 @@ atspi_set_timeout (gint val, gint startup_time)
   app_startup_time = startup_time;
 }
 
-/*
+/**
  * atspi_set_main_context:
- * @cnx: The #GmainContext to use.
+ * @cnx: The #GMainContext to use.
  *
  * Sets the main loop context that AT-SPI should assume is in use when
  * setting an idle callback.
@@ -1625,11 +1625,11 @@ atspi_set_main_context (GMainContext *cnx)
   if (process_deferred_messages_source != NULL)
   {
     g_source_destroy (process_deferred_messages_source);
-    g_source_unref (process_deferred_messages_source);
     process_deferred_messages_source = g_idle_source_new ();
     g_source_set_callback (process_deferred_messages_source,
                            process_deferred_messages_callback, NULL, NULL);
     g_source_attach (process_deferred_messages_source, cnx);
+    g_source_unref (process_deferred_messages_source);
   }
   atspi_main_context = cnx;
   atspi_dbus_connection_setup_with_g_main (atspi_get_a11y_bus (), cnx);