aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-02-03 18:38:46 -0500
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-02-03 18:46:53 -0500
commitda3f9778aff8cfa134adec3fca93c00d82bcf4af (patch)
tree383bcd68ec0808f26d14ebb727fc06257be5c4c9
parent02cda35cf7258e1d33c86f792aec30bd506221dc (diff)
downloadrneovim-da3f9778aff8cfa134adec3fca93c00d82bcf4af.tar.gz
rneovim-da3f9778aff8cfa134adec3fca93c00d82bcf4af.tar.bz2
rneovim-da3f9778aff8cfa134adec3fca93c00d82bcf4af.zip
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
-rw-r--r--src/nvim/ex_cmds.c5
-rw-r--r--src/nvim/testdir/test_autocmd.vim11
2 files changed, 15 insertions, 1 deletions
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