Skip to content

Commit 8ab3757

Browse files
committed
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.
1 parent 6bcb877 commit 8ab3757

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/ex_cmds.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,9 @@ do_ecmd(
27682768
did_decrement = close_buffer(oldwin, curbuf,
27692769
(flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE, FALSE);
27702770

2771-
the_curwin->w_closing = FALSE;
2771+
// Autocommands may have closed the window.
2772+
if (win_valid(the_curwin))
2773+
the_curwin->w_closing = FALSE;
27722774
--buf->b_locked;
27732775

27742776
#ifdef FEAT_EVAL

src/testdir/test_autocmd.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,4 +2726,15 @@ func Test_BufNew_arglocal()
27262726
au! BufNew
27272727
endfunc
27282728

2729+
func Test_autocmd_closes_window()
2730+
au BufNew,BufWinLeave * e %e
2731+
file yyy
2732+
au BufNew,BufWinLeave * ball
2733+
call assert_fails('n xxx', 'E143:')
2734+
2735+
bwipe %
2736+
au! BufNew
2737+
au! BufWinLeave
2738+
endfunc
2739+
27292740
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2464,
753755
/**/
754756
2463,
755757
/**/

0 commit comments

Comments
 (0)