mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
vim-patch:8.0.1403: using freed buffer in grep command
Problem: Using freed buffer in grep command. (gy741, Dominique Pelle)
Solution: Lock the dummy buffer to avoid autocommands wiping it out.
4fb921e388
This commit is contained in:
@@ -3909,6 +3909,7 @@ load_dummy_buffer (
|
|||||||
bufref_T newbuf_to_wipe;
|
bufref_T newbuf_to_wipe;
|
||||||
int failed = true;
|
int failed = true;
|
||||||
aco_save_T aco;
|
aco_save_T aco;
|
||||||
|
int readfile_result;
|
||||||
|
|
||||||
// Allocate a buffer without putting it in the buffer list.
|
// Allocate a buffer without putting it in the buffer list.
|
||||||
newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
|
newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
|
||||||
@@ -3922,7 +3923,9 @@ load_dummy_buffer (
|
|||||||
|
|
||||||
/* need to open the memfile before putting the buffer in a window */
|
/* need to open the memfile before putting the buffer in a window */
|
||||||
if (ml_open(newbuf) == OK) {
|
if (ml_open(newbuf) == OK) {
|
||||||
/* set curwin/curbuf to buf and save a few things */
|
// Make sure this buffer isn't wiped out by auto commands.
|
||||||
|
newbuf->b_locked++;
|
||||||
|
// set curwin/curbuf to buf and save a few things
|
||||||
aucmd_prepbuf(&aco, newbuf);
|
aucmd_prepbuf(&aco, newbuf);
|
||||||
|
|
||||||
/* Need to set the filename for autocommands. */
|
/* Need to set the filename for autocommands. */
|
||||||
@@ -3936,9 +3939,11 @@ load_dummy_buffer (
|
|||||||
curbuf->b_flags &= ~BF_DUMMY;
|
curbuf->b_flags &= ~BF_DUMMY;
|
||||||
|
|
||||||
newbuf_to_wipe.br_buf = NULL;
|
newbuf_to_wipe.br_buf = NULL;
|
||||||
if (readfile(fname, NULL,
|
readfile_result = readfile(fname, NULL, (linenr_T)0, (linenr_T)0,
|
||||||
(linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
|
(linenr_T)MAXLNUM, NULL,
|
||||||
NULL, READ_NEW | READ_DUMMY) == OK
|
READ_NEW | READ_DUMMY);
|
||||||
|
newbuf->b_locked--;
|
||||||
|
if (readfile_result == OK
|
||||||
&& !got_int
|
&& !got_int
|
||||||
&& !(curbuf->b_flags & BF_NEW)) {
|
&& !(curbuf->b_flags & BF_NEW)) {
|
||||||
failed = FALSE;
|
failed = FALSE;
|
||||||
|
@@ -797,18 +797,6 @@ func Test_QuitPre()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_Cmdline()
|
func Test_Cmdline()
|
||||||
au! CmdlineChanged : let g:text = getcmdline()
|
|
||||||
let g:text = 0
|
|
||||||
call feedkeys(":echom 'hello'\<CR>", 'xt')
|
|
||||||
call assert_equal("echom 'hello'", g:text)
|
|
||||||
au! CmdlineChanged
|
|
||||||
|
|
||||||
au! CmdlineChanged : let g:entered = expand('<afile>')
|
|
||||||
let g:entered = 0
|
|
||||||
call feedkeys(":echom 'hello'\<CR>", 'xt')
|
|
||||||
call assert_equal(':', g:entered)
|
|
||||||
au! CmdlineChanged
|
|
||||||
|
|
||||||
au! CmdlineEnter : let g:entered = expand('<afile>')
|
au! CmdlineEnter : let g:entered = expand('<afile>')
|
||||||
au! CmdlineLeave : let g:left = expand('<afile>')
|
au! CmdlineLeave : let g:left = expand('<afile>')
|
||||||
let g:entered = 0
|
let g:entered = 0
|
||||||
@@ -983,7 +971,7 @@ func Test_Cmd_Autocmds()
|
|||||||
au BufWriteCmd XtestE call extend(g:lines, getline(0, '$'))
|
au BufWriteCmd XtestE call extend(g:lines, getline(0, '$'))
|
||||||
wall " will write other window to 'lines'
|
wall " will write other window to 'lines'
|
||||||
call assert_equal(4, len(g:lines), g:lines)
|
call assert_equal(4, len(g:lines), g:lines)
|
||||||
call assert_equal('asdf', g:lines[2])
|
call assert_equal("\tasdf", g:lines[2])
|
||||||
|
|
||||||
au! BufReadCmd
|
au! BufReadCmd
|
||||||
au! BufWriteCmd
|
au! BufWriteCmd
|
||||||
|
Reference in New Issue
Block a user