Subject: Re: bug#11984: 24.1; segfault while deleting a window

From: Eli Zaretskii <[email-masked]>
Date: Sat, 21 Jul 2012 12:32:43 +0300

> From: Russell Sim <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
> Date: Sat, 21 Jul 2012 19:00:36 +1000
> 
> > Hmm, I'm not sure the core file loaded properly for me.  Can you trigger
> > the crash with Emacs running in gdb?  Do you get the following strange
> > result from printing f->output_data?
> >
> > (gdb) p f->output_data
> > $4 = {
> >   tty = 0xc2, 
> >   x = 0xc2, 
> >   w32 = 0xc2, 
> >   ns = 0xc2, 
> >   nothing = 194
> > }
> 
> (gdb) p f->output_data
> $1 = {tty = 0x0, x = 0x0, w32 = 0x0, ns = 0x0, nothing = 0}

This is a FRAME_INITIAL_P frame.

> 2652:   BLOCK_INPUT;
> 2653:   hlinfo = MOUSE_HL_INFO (f);
> 2654:   /* We are going to free the glyph matrices of WINDOW, and with that
> 2655:      we might lose any information about glyph rows that have some of
> 2656:      their glyphs highlighted in mouse face.  (These rows are marked
> 2657:      with a non-zero mouse_face_p flag.)  If WINDOW indeed has some
> 2658:      glyphs highlighted in mouse face, signal to frame's up-to-date
> 2659:      hook that mouse highlight was overwritten, so that it will
> 2660:      arrange for redisplaying the highlight.  */
> 2661:   if (EQ (hlinfo->mouse_face_window, window))
> 2662:     {
> 2663:       hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
> 2664:       hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
> 2665:       hlinfo->mouse_face_window = Qnil;
> 2666:     }

That's it your problem: you didn't include the changes below, which
make sure mouse-highlight info is never accessed for 'initial' frame
types.  The changes below were only done on the trunk, they aren't in
the emacs-24 branch.

--- src/window.c	2012-06-01 03:41:03 +0000
+++ src/window.c	2012-06-16 07:18:44 +0000
@@ -2566,7 +2566,6 @@ window-start value is reasonable when th
   Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
   ptrdiff_t startpos IF_LINT (= 0);
   int top IF_LINT (= 0), new_top, resize_failed;
-  Mouse_HLInfo *hlinfo;
 
   w = decode_any_window (window);
   XSETWINDOW (window, w);
@@ -2647,19 +2646,23 @@ window-start value is reasonable when th
     }
 
   BLOCK_INPUT;
-  hlinfo = MOUSE_HL_INFO (f);
-  /* We are going to free the glyph matrices of WINDOW, and with that
-     we might lose any information about glyph rows that have some of
-     their glyphs highlighted in mouse face.  (These rows are marked
-     with a non-zero mouse_face_p flag.)  If WINDOW indeed has some
-     glyphs highlighted in mouse face, signal to frame's up-to-date
-     hook that mouse highlight was overwritten, so that it will
-     arrange for redisplaying the highlight.  */
-  if (EQ (hlinfo->mouse_face_window, window))
-    {
-      hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
-      hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
-      hlinfo->mouse_face_window = Qnil;
+  if (!FRAME_INITIAL_P (f))
+    {
+        Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
+
+      /* We are going to free the glyph matrices of WINDOW, and with
+	 that we might lose any information about glyph rows that have
+	 some of their glyphs highlighted in mouse face.  (These rows
+	 are marked with a non-zero mouse_face_p flag.)  If WINDOW
+	 indeed has some glyphs highlighted in mouse face, signal to
+	 frame's up-to-date hook that mouse highlight was overwritten,
+	 so that it will arrange for redisplaying the highlight.  */
+      if (EQ (hlinfo->mouse_face_window, window))
+	{
+	  hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
+	  hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
+	  hlinfo->mouse_face_window = Qnil;
+	}
     }
   free_window_matrices (r);
 
@@ -3903,7 +3906,6 @@ Signal an error when WINDOW is the only 
       && EQ (r->new_total, (horflag ? r->total_cols : r->total_lines)))
     /* We can delete WINDOW now.  */
     {
-      Mouse_HLInfo *hlinfo;
 
       /* Block input.  */
       BLOCK_INPUT;
@@ -3911,9 +3913,13 @@ Signal an error when WINDOW is the only 
 
       /* If this window is referred to by the dpyinfo's mouse
 	 highlight, invalidate that slot to be safe (Bug#9904).  */
-      hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
-      if (EQ (hlinfo->mouse_face_window, window))
-	hlinfo->mouse_face_window = Qnil;
+      if (!FRAME_INITIAL_P (f))
+	{
+	  Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
+
+	  if (EQ (hlinfo->mouse_face_window, window))
+	    hlinfo->mouse_face_window = Qnil;
+	}
 
       windows_or_buffers_changed++;
       Vwindow_list = Qnil;