c078ec
From c212cb8f32c02cf2fe691372b753d334f6e25d69 Mon Sep 17 00:00:00 2001
c078ec
From: Marek Kasik <mkasik@redhat.com>
c078ec
Date: Mon, 16 Dec 2013 18:04:14 +0100
c078ec
Subject: [PATCH 1/2] gdkwindow: Handle references in "update_windows" list
c078ec
 correctly
c078ec
c078ec
Since update_windows list is a static variable in GdkWindow.c which
c078ec
contains pointers to windows which needs to be updated, it can happen
c078ec
that it contains a pointer to a window even after quit from a gtk_main().
c078ec
If another gtk_main() is called in the same process it tries to process
c078ec
windows in the list which leads to a crash.
c078ec
Correct reference count handling of added windows prevents such applications
c078ec
from crash.
c078ec
c078ec
https://bugzilla.gnome.org/show_bug.cgi?id=711552
c078ec
---
c078ec
 gdk/gdkwindow.c | 19 ++++++++++++-------
c078ec
 1 file changed, 12 insertions(+), 7 deletions(-)
c078ec
c078ec
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
c078ec
index f5f0339..0f33fb0 100644
c078ec
--- a/gdk/gdkwindow.c
c078ec
+++ b/gdk/gdkwindow.c
c078ec
@@ -5267,7 +5267,7 @@ gdk_window_add_update_window (GdkWindow *window)
c078ec
 	      prev = tmp;
c078ec
 	    }
c078ec
 	  /* here, tmp got advanced past all lower stacked siblings */
c078ec
-	  tmp = g_slist_prepend (tmp, window);
c078ec
+	  tmp = g_slist_prepend (tmp, g_object_ref (window));
c078ec
 	  if (prev)
c078ec
 	    prev->next = tmp;
c078ec
 	  else
c078ec
@@ -5280,7 +5280,7 @@ gdk_window_add_update_window (GdkWindow *window)
c078ec
        */
c078ec
       if (has_ancestor_in_list && gdk_window_is_ancestor (tmp->data, window))
c078ec
 	{
c078ec
-	  tmp = g_slist_prepend (tmp, window);
c078ec
+	  tmp = g_slist_prepend (tmp, g_object_ref (window));
c078ec
 
c078ec
 	  if (prev)
c078ec
 	    prev->next = tmp;
c078ec
@@ -5294,7 +5294,7 @@ gdk_window_add_update_window (GdkWindow *window)
c078ec
        */
c078ec
       if (! tmp->next && has_ancestor_in_list)
c078ec
 	{
c078ec
-	  tmp = g_slist_append (tmp, window);
c078ec
+	  tmp = g_slist_append (tmp, g_object_ref (window));
c078ec
 	  return;
c078ec
 	}
c078ec
 
c078ec
@@ -5305,13 +5305,20 @@ gdk_window_add_update_window (GdkWindow *window)
c078ec
    *  hierarchy than what is already in the list) or the list is
c078ec
    *  empty, prepend
c078ec
    */
c078ec
-  update_windows = g_slist_prepend (update_windows, window);
c078ec
+  update_windows = g_slist_prepend (update_windows, g_object_ref (window));
c078ec
 }
c078ec
 
c078ec
 static void
c078ec
 gdk_window_remove_update_window (GdkWindow *window)
c078ec
 {
c078ec
-  update_windows = g_slist_remove (update_windows, window);
c078ec
+  GSList *link;
c078ec
+
c078ec
+  link = g_slist_find (update_windows, window);
c078ec
+  if (link != NULL)
c078ec
+    {
c078ec
+      update_windows = g_slist_delete_link (update_windows, link);
c078ec
+      g_object_unref (window);
c078ec
+    }
c078ec
 }
c078ec
 
c078ec
 static gboolean
c078ec
@@ -5687,8 +5694,6 @@ gdk_window_process_all_updates (void)
c078ec
 
c078ec
   _gdk_windowing_before_process_all_updates ();
c078ec
 
c078ec
-  g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
c078ec
-
c078ec
   while (tmp_list)
c078ec
     {
c078ec
       GdkWindowObject *private = (GdkWindowObject *)tmp_list->data;
c078ec
-- 
c078ec
1.8.4.2
c078ec