diff src/quickfix.c @ 13056:b931b2751650 v8.0.1403

patch 8.0.1403: using freed buffer in grep command commit https://github.com/vim/vim/commit/4fb921e388b9a042573ab06cce36e92874954197 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 18 15:33:00 2017 +0100 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.
author Christian Brabandt <cb@256bit.org>
date Mon, 18 Dec 2017 15:45:04 +0100
parents 7c0e0e923537
children 6479dadcf214
line wrap: on
line diff
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4572,6 +4572,7 @@ load_dummy_buffer(
     bufref_T	newbuf_to_wipe;
     int		failed = TRUE;
     aco_save_T	aco;
+    int		readfile_result;
 
     /* Allocate a buffer without putting it in the buffer list. */
     newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
@@ -4585,6 +4586,9 @@ load_dummy_buffer(
     /* need to open the memfile before putting the buffer in a window */
     if (ml_open(newbuf) == OK)
     {
+	/* 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);
 
@@ -4599,9 +4603,11 @@ load_dummy_buffer(
 	curbuf->b_flags &= ~BF_DUMMY;
 
 	newbuf_to_wipe.br_buf = NULL;
-	if (readfile(fname, NULL,
+	readfile_result = readfile(fname, NULL,
 		    (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
-		    NULL, READ_NEW | READ_DUMMY) == OK
+		    NULL, READ_NEW | READ_DUMMY);
+	--newbuf->b_locked;
+	if (readfile_result == OK
 		&& !got_int
 		&& !(curbuf->b_flags & BF_NEW))
 	{