--- gmain.c.save	2005-06-06 20:40:04.389273512 +0200
+++ gmain.c	2005-06-06 20:43:47.614505464 +0200
@@ -1888,6 +1888,7 @@
 {
   gint *depth = get_depth_pointer ();
   guint i;
+  GPtrArray *to_process = g_ptr_array_new ();
 
   for (i = 0; i < context->pending_dispatches->len; i++)
     {
@@ -1896,6 +1897,15 @@
       context->pending_dispatches->pdata[i] = NULL;
       g_assert (source);
 
+      g_ptr_array_add (to_process, source);
+    }
+
+  g_ptr_array_set_size (context->pending_dispatches, 0);
+
+  for (i = 0; i < to_process->len; i++)
+    {
+
+      GSource *source = to_process->pdata[i];
       source->flags &= ~G_SOURCE_READY;
 
       if (!SOURCE_DESTROYED (source))
@@ -1960,7 +1970,7 @@
       SOURCE_UNREF (source, context);
     }
 
-  g_ptr_array_set_size (context->pending_dispatches, 0);
+  g_ptr_array_free (to_process, TRUE);
 }
 
 /* Holds context's lock */

