Subject: bug#31312: Segmentation fault with doom-emacs, NeoTree and Zoom

From: Eli Zaretskii <[email-masked]>
Date: Wed, 02 May 2018 14:52:55 +0300

On May 2, 2018 9:16:26 AM GMT+03:00, martin rudalics <[email-masked]> wrote:
> >> Is w in reconsider_clip_changes the same as XWINDOW
> (selected_window)
>  >> when it fails?
>  >
>  > Nope.  In fact, doing
>  >
>  >      break 13939 if (w != XWINDOW(selected_window))
>  >
>  > triggers only just before the bad reconsider_clip_changes call.
>  >
>  > #0  redisplay_internal () at ../../src/xdisp.c:13939
>  > #1  0x0000000000463c16 in redisplay () at ../../src/xdisp.c:13518
> > #2  0x00000000005851ae in read_char (commandflag=1,
> map=XIL(0x5e99db3), prev_event=XIL(0),
> >      used_mouse_menu=0x7fffffffe41f, end_time=0x0) at
> ../../src/keyboard.c:2480
> > #3  0x00000000005957c5 in read_key_sequence (keybuf=0x7fffffffe570,
> bufsize=30, prompt=XIL(0),
> >      dont_downcase_last=false, can_return_switch_frame=true,
> fix_current_buffer=true,
>  >      prevent_redisplay=false) at ../../src/keyboard.c:9147
> > #4  0x0000000000581d55 in command_loop_1 () at
> ../../src/keyboard.c:1368
>  > (More stack frames follow...)
>  > (gdb) p w
>  > $16 = (struct window *) 0x47d22f0
>  > (gdb) p sw
>  > $17 = (struct window *) 0x47d22f0
>  > (gdb) p XWINDOW(selected_window)
>  > $18 = (struct window *) 0x61109d0
>  > (gdb) p w->contents
>  > $19 = XIL(0)
>  > (gdb) p XWINDOW(selected_window)->contents
>  > $20 = XIL(0x493e565)
>  > (gdb) xpr
>  > Lisp_Vectorlike
>  > PVEC_BUFFER
>  > $21 = (struct buffer *) 0x493e560
>  > (unsigned char *) 0x4a34568 " *NeoTree*"
> 
> I'm probably too silly to understand this.  IIUC we are here
> 
>    /* do_pending_window_change could change the selected_window due to
>       frame resizing which makes the selected window too small.  */
> if (WINDOWP (selected_window) && (w = XWINDOW (selected_window)) !=
> sw)
>      sw = w;
> 
>    /* Clear frames marked as garbaged.  */
>    clear_garbaged_frames ();
> 
>    /* Build menubar and tool-bar items.  */
>    if (NILP (Vmemory_full))
>      prepare_menu_bars ();
> 
>    reconsider_clip_changes (w);
> 
> and the only ways this could cause w != XWINDOW(selected_window)
> before the last call is either !WINDOWP (selected_window) or that
> clear_garbaged_frames or prepare_menu_bars change selected_window.
> Can you find the responsible?
> 
> martin

Those are exactly the questions I'd like to have answers for.

Btw, I tried to run the recipe in "emacs -Q", and it didn't crash, so I guess
something in doom-land is a necessary piece of this puzzle.

Also, please take a look at zoom.el: it hooks window-size-change-functions
and resizes the windows in that hook(!).  And prepare_menu_bars runs
window-size-change-functions, which resets the frame's
window-configuration-changed flag, assuming that no one in their right
mind will change the configuration from a hook that notifies about
changes in configuration.

After all this madness, it's small wonder that we end up with a dead
window in W.

Of course, we need to protect us against such calamities in any case...