]> granicus.if.org Git - vim/commitdiff
patch 8.0.1403: using freed buffer in grep command v8.0.1403
authorBram Moolenaar <Bram@vim.org>
Mon, 18 Dec 2017 14:33:00 +0000 (15:33 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 18 Dec 2017 14:33:00 +0000 (15:33 +0100)
Problem:    Using freed buffer in grep command. (gy741, Dominique Pelle)
Solution:   Lock the dummy buffer to avoid autocommands wiping it out.

src/quickfix.c
src/testdir/test_autocmd.vim
src/version.c

index 70522fa62a29d1d60872e60bc658aff71f1c931a..6817aa72619b07d9465c9e8cec792bc392ece2d5 100644 (file)
@@ -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))
        {
index 8ac8811075aa3c4f5d9fecc747a14807b2eb8f3e..d8fddffebb7467701cbb54f824bc4e272623edb5 100644 (file)
@@ -1171,3 +1171,10 @@ func Test_nocatch_wipe_all_buffers()
   bwipe
   au!
 endfunc
+
+func Test_nocatch_wipe_dummy_buffer()
+  " Nasty autocommand: wipe buffer on any event.
+  au * x bwipe
+  call assert_fails('lv½ /x', 'E480')
+  au!
+endfunc
index fc2eda65e471762d1773d8f34b2c6567604ba778..1ce42a91d5448543f59b754b1695f089bb159847 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1403,
 /**/
     1402,
 /**/