--- glib-2.36.0/glib/gmain.c.orig	2013-04-09 02:13:11 +0400
+++ glib-2.36.0/glib/gmain.c	2013-04-09 03:07:13 +0400
@@ -357,12 +357,12 @@
 #define SOURCE_DESTROYED(source) (((source)->flags & G_HOOK_FLAG_ACTIVE) == 0)
 #define SOURCE_BLOCKED(source) (((source)->flags & G_SOURCE_BLOCKED) != 0)
 
-#define SOURCE_UNREF(source, context)                       \
+#define SOURCE_UNREF(source, context, have_lock)                       \
    G_STMT_START {                                           \
     if ((source)->ref_count > 1)                            \
       (source)->ref_count--;                                \
     else                                                    \
-      g_source_unref_internal ((source), (context), TRUE);  \
+      g_source_unref_internal ((source), (context), have_lock);  \
    } G_STMT_END
 
 
@@ -395,9 +395,10 @@
 				     GMainContext  *context,
 				     gboolean       may_modify);
 static gboolean g_source_iter_next  (GSourceIter   *iter,
-				     GSource      **source);
-static void     g_source_iter_clear (GSourceIter   *iter);
-
+				     GSource      **source,
+				     int            have_lock);
+static void     g_source_iter_clear (GSourceIter   *iter,
+				     int            have_lock);
 static gboolean g_timeout_dispatch (GSource     *source,
 				    GSourceFunc  callback,
 				    gpointer     user_data);
@@ -539,7 +540,7 @@
 
   //LOCK_CONTEXT (context);
   g_source_iter_init (&iter, context, TRUE);
-  while (g_source_iter_next (&iter, &source))
+  while (g_source_iter_next (&iter, &source, FALSE))
     {
       source->context = NULL;
       g_source_destroy_internal (source, context, FALSE);
@@ -896,7 +897,7 @@
 
 /* Holds context's lock */
 static gboolean
-g_source_iter_next (GSourceIter *iter, GSource **source)
+g_source_iter_next (GSourceIter *iter, GSource **source, int have_lock)
 {
   GSource *next_source;
 
@@ -927,7 +928,7 @@
    */
 
   if (iter->source && iter->may_modify)
-    SOURCE_UNREF (iter->source, iter->context);
+    SOURCE_UNREF (iter->source, iter->context, have_lock);
   iter->source = next_source;
   if (iter->source && iter->may_modify)
     iter->source->ref_count++;
@@ -940,11 +941,11 @@
  * the g_source_iter_next() loop early.
  */
 static void
-g_source_iter_clear (GSourceIter *iter)
+g_source_iter_clear (GSourceIter *iter, int have_lock)
 {
   if (iter->source && iter->may_modify)
     {
-      SOURCE_UNREF (iter->source, iter->context);
+      SOURCE_UNREF (iter->source, iter->context, have_lock);
       iter->source = NULL;
     }
 }
@@ -1091,7 +1092,7 @@
       context->overflow_used_source_ids = g_hash_table_new (NULL, NULL);
   
       g_source_iter_init (&iter, context, FALSE);
-      while (g_source_iter_next (&iter, &source))
+      while (g_source_iter_next (&iter, &source, TRUE))
         {
           g_hash_table_add (context->overflow_used_source_ids,
                             GUINT_TO_POINTER (source->source_id));
@@ -2078,13 +2079,13 @@
   LOCK_CONTEXT (context);
   
   g_source_iter_init (&iter, context, FALSE);
-  while (g_source_iter_next (&iter, &source))
+  while (g_source_iter_next (&iter, &source, TRUE))
     {
       if (!SOURCE_DESTROYED (source) &&
 	  source->source_id == source_id)
 	break;
     }
-  g_source_iter_clear (&iter);
+  g_source_iter_clear (&iter, TRUE);
 
   UNLOCK_CONTEXT (context);
 
@@ -2119,7 +2120,7 @@
   LOCK_CONTEXT (context);
 
   g_source_iter_init (&iter, context, FALSE);
-  while (g_source_iter_next (&iter, &source))
+  while (g_source_iter_next (&iter, &source, TRUE))
     {
       if (!SOURCE_DESTROYED (source) &&
 	  source->source_funcs == funcs &&
@@ -2134,7 +2135,7 @@
 	    break;
 	}
     }
-  g_source_iter_clear (&iter);
+  g_source_iter_clear (&iter, TRUE);
 
   UNLOCK_CONTEXT (context);
 
@@ -2165,7 +2166,7 @@
   LOCK_CONTEXT (context);
 
   g_source_iter_init (&iter, context, FALSE);
-  while (g_source_iter_next (&iter, &source))
+  while (g_source_iter_next (&iter, &source, TRUE))
     {
       if (!SOURCE_DESTROYED (source) &&
 	  source->callback_funcs)
@@ -2179,7 +2180,7 @@
 	    break;
 	}
     }
-  g_source_iter_clear (&iter);
+  g_source_iter_clear (&iter, TRUE);
 
   UNLOCK_CONTEXT (context);
 
@@ -3098,7 +3099,7 @@
 	    }
 	}
       
-      SOURCE_UNREF (source, context);
+      SOURCE_UNREF (source, context, TRUE);
     }
 
   g_ptr_array_set_size (context->pending_dispatches, 0);
@@ -3313,7 +3314,7 @@
   for (i = 0; i < context->pending_dispatches->len; i++)
     {
       if (context->pending_dispatches->pdata[i])
-	SOURCE_UNREF ((GSource *)context->pending_dispatches->pdata[i], context);
+	SOURCE_UNREF ((GSource *)context->pending_dispatches->pdata[i], context, TRUE);
     }
   g_ptr_array_set_size (context->pending_dispatches, 0);
   
@@ -3322,7 +3323,7 @@
   context->timeout = -1;
   
   g_source_iter_init (&iter, context, TRUE);
-  while (g_source_iter_next (&iter, &source))
+  while (g_source_iter_next (&iter, &source, TRUE))
     {
       gint source_timeout = -1;
 
@@ -3407,7 +3408,7 @@
 	    context->timeout = MIN (context->timeout, source_timeout);
 	}
     }
-  g_source_iter_clear (&iter);
+  g_source_iter_clear (&iter, TRUE);
 
   UNLOCK_CONTEXT (context);
   
@@ -3541,7 +3542,7 @@
     }
 
   g_source_iter_init (&iter, context, TRUE);
-  while (g_source_iter_next (&iter, &source))
+  while (g_source_iter_next (&iter, &source, TRUE))
     {
       if (SOURCE_DESTROYED (source) || SOURCE_BLOCKED (source))
 	continue;
@@ -3626,7 +3627,7 @@
           max_priority = source->priority;
 	}
     }
-  g_source_iter_clear (&iter);
+  g_source_iter_clear (&iter, TRUE);
 
   UNLOCK_CONTEXT (context);
 
