summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-02-03 21:56:59 +0100
committerBram Moolenaar <Bram@vim.org>2021-02-03 21:56:59 +0100
commit8ab375706e6712308f8cf7529bcae56684a6f385 (patch)
tree2bb4334168ae77eca7c116f89b84ecb1807871a4 /src
parent6bcb877ec19a647443195a54eeac60cb693fd827 (diff)
patch 8.2.2464: using freed memory if window closed in autocommandv8.2.2464
Problem: Using freed memory if window closed in autocommand. (houyunsong) Solution: Check the window still exists.
Diffstat (limited to 'src')
-rw-r--r--src/ex_cmds.c4
-rw-r--r--src/testdir/test_autocmd.vim11
-rw-r--r--src/version.c2
3 files changed, 16 insertions, 1 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index b678f6699c..b6e1cbf7f0 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2768,7 +2768,9 @@ do_ecmd(
did_decrement = close_buffer(oldwin, curbuf,
(flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE, 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;
#ifdef FEAT_EVAL
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 71f8d2d60c..b1a235c8f2 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -2726,4 +2726,15 @@ func Test_BufNew_arglocal()
au! BufNew
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
diff --git a/src/version.c b/src/version.c
index 53ed13c73a..a93b81a410 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2464,
+/**/
2463,
/**/
2462,