Skip to content

Commit 0ea5070

Browse files
committed
patch 8.0.0700: segfault with QuitPre autocommand closes the window
Problem: Segfault with QuitPre autocommand closes the window. (Marek) Solution: Check that the window pointer is still valid. (Christian Brabandt, closes #1817)
1 parent 710b4a1 commit 0ea5070

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/ex_docmd.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7271,8 +7271,11 @@ ex_quit(exarg_T *eap)
72717271
apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf);
72727272
/* Refuse to quit when locked or when the buffer in the last window is
72737273
* being closed (can only happen in autocommands). */
7274-
if (curbuf_locked() || (wp->w_buffer->b_nwindows == 1
7275-
&& wp->w_buffer->b_locked > 0))
7274+
if (curbuf_locked()
7275+
# ifdef FEAT_WINDOWS
7276+
|| !win_valid(wp)
7277+
# endif
7278+
|| (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0))
72767279
return;
72777280
#endif
72787281

src/testdir/test_tabpage.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,5 +473,23 @@ func Test_tabnext_on_buf_unload2()
473473
endwhile
474474
endfunc
475475

476+
func Test_close_on_quitpre()
477+
" This once caused a crash
478+
new
479+
only
480+
set bufhidden=delete
481+
au QuitPre <buffer> close
482+
tabnew tab1
483+
tabnew tab2
484+
1tabn
485+
q!
486+
call assert_equal(1, tabpagenr())
487+
call assert_equal(2, tabpagenr('$'))
488+
" clean up
489+
while tabpagenr('$') > 1
490+
bwipe!
491+
endwhile
492+
1b
493+
endfunc
476494

477495
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
700,
767769
/**/
768770
699,
769771
/**/

0 commit comments

Comments
 (0)