From 0ea5070d79c8a13fb2403280a72f968495b0fab7 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 8 Jul 2017 14:44:50 +0200 Subject: [PATCH] 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) --- src/ex_docmd.c | 7 +++++-- src/testdir/test_tabpage.vim | 18 ++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 6ff578e65..8f427cfde 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -7271,8 +7271,11 @@ ex_quit(exarg_T *eap) apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf); /* Refuse to quit when locked or when the buffer in the last window is * being closed (can only happen in autocommands). */ - if (curbuf_locked() || (wp->w_buffer->b_nwindows == 1 - && wp->w_buffer->b_locked > 0)) + if (curbuf_locked() +# ifdef FEAT_WINDOWS + || !win_valid(wp) +# endif + || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0)) return; #endif diff --git a/src/testdir/test_tabpage.vim b/src/testdir/test_tabpage.vim index c139958df..239b1b965 100644 --- a/src/testdir/test_tabpage.vim +++ b/src/testdir/test_tabpage.vim @@ -473,5 +473,23 @@ func Test_tabnext_on_buf_unload2() endwhile endfunc +func Test_close_on_quitpre() + " This once caused a crash + new + only + set bufhidden=delete + au QuitPre close + tabnew tab1 + tabnew tab2 + 1tabn + q! + call assert_equal(1, tabpagenr()) + call assert_equal(2, tabpagenr('$')) + " clean up + while tabpagenr('$') > 1 + bwipe! + endwhile + 1b +endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 8cbbbf773..7c1fb103a 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 700, /**/ 699, /**/ -- 2.50.1