Skip to content

Commit 4fb921e

Browse files
committed
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.
1 parent 9bca805 commit 4fb921e

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/quickfix.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4572,6 +4572,7 @@ load_dummy_buffer(
45724572
bufref_T newbuf_to_wipe;
45734573
int failed = TRUE;
45744574
aco_save_T aco;
4575+
int readfile_result;
45754576

45764577
/* Allocate a buffer without putting it in the buffer list. */
45774578
newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
@@ -4585,6 +4586,9 @@ load_dummy_buffer(
45854586
/* need to open the memfile before putting the buffer in a window */
45864587
if (ml_open(newbuf) == OK)
45874588
{
4589+
/* Make sure this buffer isn't wiped out by auto commands. */
4590+
++newbuf->b_locked;
4591+
45884592
/* set curwin/curbuf to buf and save a few things */
45894593
aucmd_prepbuf(&aco, newbuf);
45904594

@@ -4599,9 +4603,11 @@ load_dummy_buffer(
45994603
curbuf->b_flags &= ~BF_DUMMY;
46004604

46014605
newbuf_to_wipe.br_buf = NULL;
4602-
if (readfile(fname, NULL,
4606+
readfile_result = readfile(fname, NULL,
46034607
(linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
4604-
NULL, READ_NEW | READ_DUMMY) == OK
4608+
NULL, READ_NEW | READ_DUMMY);
4609+
--newbuf->b_locked;
4610+
if (readfile_result == OK
46054611
&& !got_int
46064612
&& !(curbuf->b_flags & BF_NEW))
46074613
{

src/testdir/test_autocmd.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,3 +1171,10 @@ func Test_nocatch_wipe_all_buffers()
11711171
bwipe
11721172
au!
11731173
endfunc
1174+
1175+
func Test_nocatch_wipe_dummy_buffer()
1176+
" Nasty autocommand: wipe buffer on any event.
1177+
au * x bwipe
1178+
call assert_fails('lv½ /x', 'E480')
1179+
au!
1180+
endfunc

src/version.c

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

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1403,
774776
/**/
775777
1402,
776778
/**/

0 commit comments

Comments
 (0)