[sawfish/sawfish-1.5.0] Fixed a race condition which lead to segfault, if a window is mapped and immediately unmapped



commit 745286943137e4b2593e3461401c5d89ff05549f
Author: Christopher Roy Bratusek <chris nanolx org>
Date:   Fri Oct 9 22:19:24 2009 +0200

    Fixed a race condition which lead to segfault, if a window is mapped and immediately unmapped

 ChangeLog     |    5 +++++
 man/news.texi |   12 ++++++++++++
 src/windows.c |   20 ++++++++++++++------
 3 files changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 64406e1..fac81da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-10-09  Christopher Bratusek <zanghar freenet de>
+	* src/windows.c: fixed a race condition which may lead to a crash, if
+	                 a window is mapped and immediately unmapped
+			 -- [Janek Kozicki, Timo Korvola]
+
 2009-09-20  Christopher Bratusek <zanghar freenet de>
 	* themes/Crux/theme.jl: make default text-color of inactive frames black
 	                          for better readability
diff --git a/man/news.texi b/man/news.texi
index f31aa72..b2969e7 100644
--- a/man/news.texi
+++ b/man/news.texi
@@ -6,6 +6,18 @@ This lists the user-visible changes made to Sawfish, and which releases
 they occurred between. For more detailed information see the
 @file{ChangeLog} file in the Sawfish source tree.
 
+ heading 1.5.3
+
+ itemize @bullet
+
+ item The 1.5.3 release has backports from 1.6.0 (HEAD)
+
+ item Bugs fixed:
+ itemize @minus
+
+ item Fixed a race condition which lead to segfault, if a window is mapped and immediately unmapped [Janek Kozicki, Timo Korvola]
+ end itemize
+ end itemize
 @heading 1.5.2
 
 @itemize @bullet
diff --git a/src/windows.c b/src/windows.c
index baf924a..71617f0 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -459,6 +459,10 @@ add_window (Window id)
 	w->net_name = Qnil;
 	w->net_icon_name = Qnil;
 
+        /* Don't garbage collect the window before we are done. */
+        /* Note: must not return without rep_POPGC. */
+	rep_PUSHGC(gc_win, win);
+
 	/* have to put it somewhere until it finds the right place */
 	insert_in_stacking_list_above_all (w);
 	restack_window (w);
@@ -525,12 +529,17 @@ add_window (Window id)
 			    (rep_VAL (&iconify_mod), Qiconify_window),
 			    rep_VAL(w));
 	  }
-	
+
+		
+	/* Prevent hook call on non existing window */
+	if (WINDOW_IS_GONE_P (w))
+	{
+		rep_POPGC;
+		return 0;
+	}
 	/* ..then call the add-window-hook's.. */
-	rep_PUSHGC(gc_win, win);
 	Fcall_window_hook (Qbefore_add_window_hook, rep_VAL(w), Qnil, Qnil);
 	Fcall_window_hook (Qadd_window_hook, rep_VAL(w), Qnil, Qnil);
-	rep_POPGC;
 
 	/* In case the window disappeared during the hook call */
 	if (!WINDOW_IS_GONE_P (w))
@@ -551,13 +560,11 @@ add_window (Window id)
 
 	if (!WINDOW_IS_GONE_P (w))
 	{
-           repv tem = Fwindow_get (rep_VAL(w), Qplaced, Qnil);
+            repv tem = Fwindow_get (rep_VAL(w), Qplaced, Qnil);
 	    if (initialising || (tem && tem == Qnil))
 	    {
 		/* ..then the place-window-hook.. */
-		rep_PUSHGC(gc_win, win);
 		Fcall_window_hook (Qplace_window_hook, rep_VAL(w), Qnil, Qor);
-		rep_POPGC;
 	    }
 	}
 	Fwindow_put (rep_VAL(w), Qplaced, Qt);
@@ -570,6 +577,7 @@ add_window (Window id)
 	    /* Tell the window where it ended up.. */
 	    send_synthetic_configure (w);
 	}
+        rep_POPGC;
     }
     return w;
 }



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