From c9195a1273159bfd227bfa9a7b407888d0d18110 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 11 May 2021 22:27:21 -0400 Subject: vim-patch:8.2.2473: crash when leaving command line window triggers autocommand Problem: Crash when leaving command line window triggers autocommand. (houyunsong) Solution: Make sure not to close the current window or buffer. https://github.com/vim/vim/commit/8c6951fa2836a1ae3257770e7b927a9380439912 N/A patches for version.c: vim-patch:8.2.2414: using freed memory when closing the cmdline window Problem: Using freed memory when closing the cmdline window. Solution: Check the window is still valid. https://github.com/vim/vim/commit/b7e2670b6a1de02c772af5097ba24f2a15b26eec --- src/nvim/ex_getln.c | 8 +++++--- src/nvim/testdir/test_autocmd.vim | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 53571ec8da..43762e8d6b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -6635,11 +6635,13 @@ static int open_cmdwin(void) wp = curwin; set_bufref(&bufref, curbuf); win_goto(old_curwin); - win_close(wp, true); + if (win_valid(wp) && wp != curwin) { + win_close(wp, true); + } // win_close() may have already wiped the buffer when 'bh' is - // set to 'wipe'. - if (bufref_valid(&bufref)) { + // set to 'wipe', autocommands may have closed other windows + if (bufref_valid(&bufref) && bufref.br_buf != curbuf) { close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, false); } diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index e0a04c94f8..bb84fa498e 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -2000,4 +2000,13 @@ func Test_autocmd_closes_window() au! BufWinLeave endfunc +func Test_autocmd_closing_cmdwin() + au BufWinLeave * nested q + call assert_fails("norm 7q?\n", 'E855:') + + au! BufWinLeave + new + only +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit