From da3f9778aff8cfa134adec3fca93c00d82bcf4af Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 3 Feb 2021 18:38:46 -0500 Subject: vim-patch:8.2.2464: using freed memory if window closed in autocommand Problem: Using freed memory if window closed in autocommand. (houyunsong) Solution: Check the window still exists. https://github.com/vim/vim/commit/8ab375706e6712308f8cf7529bcae56684a6f385 --- src/nvim/ex_cmds.c | 5 ++++- src/nvim/testdir/test_autocmd.vim | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 6b96c4deca..9239eb5ca6 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2416,7 +2416,10 @@ int do_ecmd( (flags & ECMD_HIDE) || curbuf->terminal ? 0 : DOBUF_UNLOAD, false); - the_curwin->w_closing = false; + // Autocommands may have closed the window. + if (win_valid(the_curwin)) { + the_curwin->w_closing = false; + } buf->b_locked--; // autocmds may abort script processing diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 374ad65aa9..1f3a45a9ab 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1939,4 +1939,15 @@ func Test_autocmd_window() %bw! endfunc +func Test_autocmd_closes_window() + au BufNew,BufWinLeave * e %e + file yyy + au BufNew,BufWinLeave * ball + call assert_fails('n xxx', 'E143:') + + bwipe % + au! BufNew + au! BufWinLeave +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit