vim-patch:7.4.2006

Problem:    Crash when using tabnext in BufUnload autocmd. (Norio Takagi)
Solution:   First check that the current buffer is the right one. (Hirohito
            Higashi)

30445cb6e9
This commit is contained in:
rover 2017-01-07 22:56:51 +08:00
parent b4c0c61f5c
commit 888cdce3aa
3 changed files with 29 additions and 9 deletions

View File

@ -406,9 +406,6 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
buf->b_nwindows = nwindows;
buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0));
if (win_valid_any_tab(win) && win->w_buffer == buf) {
win->w_buffer = NULL; // make sure we don't use the buffer now
}
/* Autocommands may have deleted the buffer. */
if (!buf_valid(buf))
@ -416,11 +413,6 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
if (aborting()) /* autocmds may abort script processing */
return;
/* Autocommands may have opened or closed windows for this buffer.
* Decrement the count for the close we do here. */
if (buf->b_nwindows > 0)
--buf->b_nwindows;
/*
* It's possible that autocommands change curbuf to the one being deleted.
* This might cause the previous curbuf to be deleted unexpectedly. But
@ -431,6 +423,16 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
if (buf == curbuf && !is_curbuf)
return;
if (win_valid_any_tab(win) && win->w_buffer == buf) {
win->w_buffer = NULL; // make sure we don't use the buffer now
}
// Autocommands may have opened or closed windows for this buffer.
// Decrement the count for the close we do here.
if (buf->b_nwindows > 0) {
buf->b_nwindows--;
}
/* Change directories when the 'acd' option is set. */
do_autochdir();

View File

@ -64,6 +64,24 @@ function Test_bufunload()
augroup! test_bufunload_group
endfunc
" SEGV occurs in older versions. (At least 7.4.2005 or older)
function Test_autocmd_bufunload_with_tabnext()
tabedit
tabfirst
augroup test_autocmd_bufunload_with_tabnext_group
autocmd!
autocmd BufUnload <buffer> tabnext
augroup END
quit
call assert_equal(2, tabpagenr('$'))
augroup! test_autocmd_bufunload_with_tabnext_group
tablast
quit
endfunc
func s:AddAnAutocmd()
augroup vimBarTest
au BufReadCmd * echo 'hello'

View File

@ -434,7 +434,7 @@ static int included_patches[] = {
// 2009,
// 2008,
2007,
// 2006,
2006,
2005,
// 2004 NA
// 2003 NA