Skip to content

Commit 2573af3

Browse files
committed
patch 8.2.0381: using freed memory with :lvimgrep and autocommand
Problem: Using freed memory with :lvimgrep and autocommand. (extracted from POC by Dominique Pelle) Solution: Avoid deleting a dummy buffer used in a window. (closes #5777)
1 parent 1939826 commit 2573af3

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/quickfix.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6268,7 +6268,26 @@ load_dummy_buffer(
62686268
static void
62696269
wipe_dummy_buffer(buf_T *buf, char_u *dirname_start)
62706270
{
6271-
if (curbuf != buf) // safety check
6271+
// If any autocommand opened a window on the dummy buffer, close that
6272+
// window. If we can't close them all then give up.
6273+
while (buf->b_nwindows > 0)
6274+
{
6275+
int did_one = FALSE;
6276+
win_T *wp;
6277+
6278+
if (firstwin->w_next != NULL)
6279+
for (wp = firstwin; wp != NULL; wp = wp->w_next)
6280+
if (wp->w_buffer == buf)
6281+
{
6282+
if (win_close(wp, FALSE) == OK)
6283+
did_one = TRUE;
6284+
break;
6285+
}
6286+
if (!did_one)
6287+
return;
6288+
}
6289+
6290+
if (curbuf != buf && buf->b_nwindows == 0) // safety check
62726291
{
62736292
#if defined(FEAT_EVAL)
62746293
cleanup_T cs;

src/testdir/test_quickfix.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,6 +3684,14 @@ func Test_lvimgrep_crash()
36843684
enew | only
36853685
endfunc
36863686

3687+
func Test_lvimgrep_crash2()
3688+
au BufNewFile x sfind
3689+
call assert_fails('lvimgrep x x', 'E480:')
3690+
call assert_fails('lvimgrep x x x', 'E480:')
3691+
3692+
au! BufNewFile
3693+
endfunc
3694+
36873695
" Test for the position of the quickfix and location list window
36883696
func Test_qfwin_pos()
36893697
" Open two windows

src/version.c

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

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
381,
741743
/**/
742744
380,
743745
/**/

0 commit comments

Comments
 (0)