]> granicus.if.org Git - vim/commitdiff
patch 8.2.2464: using freed memory if window closed in autocommand v8.2.2464
authorBram Moolenaar <Bram@vim.org>
Wed, 3 Feb 2021 20:56:59 +0000 (21:56 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 3 Feb 2021 20:56:59 +0000 (21:56 +0100)
Problem:    Using freed memory if window closed in autocommand. (houyunsong)
Solution:   Check the window still exists.

src/ex_cmds.c
src/testdir/test_autocmd.vim
src/version.c

index b678f6699cb4a60bb7b3bcf3e9123144c6ea65be..b6e1cbf7f059501ed170b5eb8b8fb06d435cb149 100644 (file)
@@ -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
index 71f8d2d60ce4d6fd97c23549c55fbe9f2a64f715..b1a235c8f2c0ed84f591b8ab19a303dc6747fb14 100644 (file)
@@ -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
index 53ed13c73a833df04e286d774863911714ea5245..a93b81a4107b5be9641b13f7d2227d090c0a1bb1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2464,
 /**/
     2463,
 /**/