0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

updated for version 7.4a.042

Problem:    Crash when BufUnload autocommands close all buffers. (Andrew
            Pimlott)
Solution:   Set curwin->w_buffer to curbuf to avoid NULL.
This commit is contained in:
Bram Moolenaar
2013-07-24 16:02:36 +02:00
parent ad875fb7ff
commit 2b90ed294e
4 changed files with 31 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
Test for BufWritePre autocommand that deletes or unloads the buffer. Test for BufWritePre autocommand that deletes or unloads the buffer.
Test for BufUnload autocommand that unloads all other buffers.
STARTTEST STARTTEST
:so small.vim :so small.vim
@@ -16,6 +17,27 @@ $r2:.,/end of/w! Xxx2 " write test file Xxx2
:bwipe test.out " remove test.out from the buffer list :bwipe test.out " remove test.out from the buffer list
:w " write it, will delete the buffer and give an error msg :w " write it, will delete the buffer and give an error msg
:w >>test.out " Append contents of this file :w >>test.out " Append contents of this file
:au! BufWritePre
:func CloseAll()
let i = 0
while i <= bufnr('$')
if i != bufnr('%') && bufloaded(i)
exe i . "bunload"
endif
let i += 1
endwhile
endfunc
:func WriteToOut()
edit! test.out
$put ='VimLeave done'
write
endfunc
:set viminfo='100,nviminfo
:au BufUnload * call CloseAll()
:au VimLeave * call WriteToOut()
:e small.vim
:sp mbyte.vim
:q
:qa! :qa!
ENDTEST ENDTEST

View File

@@ -4,3 +4,4 @@ end of Xxx
start of Xxx1 start of Xxx1
test test
end of Xxx end of Xxx
VimLeave done

View File

@@ -727,6 +727,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
42,
/**/ /**/
41, 41,
/**/ /**/

View File

@@ -2291,8 +2291,13 @@ win_close(win, free_buf)
if (only_one_window() && win_valid(win) && win->w_buffer == NULL if (only_one_window() && win_valid(win) && win->w_buffer == NULL
&& (last_window() || curtab != prev_curtab && (last_window() || curtab != prev_curtab
|| close_last_window_tabpage(win, free_buf, prev_curtab))) || close_last_window_tabpage(win, free_buf, prev_curtab)))
/* Autocommands have close all windows, quit now. */ {
/* Autocommands have close all windows, quit now. Restore
* curwin->w_buffer, otherwise writing viminfo may fail. */
if (curwin->w_buffer == NULL)
curwin->w_buffer = curbuf;
getout(0); getout(0);
}
/* Autocommands may have closed the window already, or closed the only /* Autocommands may have closed the window already, or closed the only
* other window or moved to another tab page. */ * other window or moved to another tab page. */