comparison 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
comparison
equal deleted inserted replaced
13055:cd0f518fd36c 13056:b931b2751650
4570 buf_T *newbuf; 4570 buf_T *newbuf;
4571 bufref_T newbufref; 4571 bufref_T newbufref;
4572 bufref_T newbuf_to_wipe; 4572 bufref_T newbuf_to_wipe;
4573 int failed = TRUE; 4573 int failed = TRUE;
4574 aco_save_T aco; 4574 aco_save_T aco;
4575 int readfile_result;
4575 4576
4576 /* Allocate a buffer without putting it in the buffer list. */ 4577 /* Allocate a buffer without putting it in the buffer list. */
4577 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); 4578 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
4578 if (newbuf == NULL) 4579 if (newbuf == NULL)
4579 return NULL; 4580 return NULL;
4583 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); 4584 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP);
4584 4585
4585 /* need to open the memfile before putting the buffer in a window */ 4586 /* need to open the memfile before putting the buffer in a window */
4586 if (ml_open(newbuf) == OK) 4587 if (ml_open(newbuf) == OK)
4587 { 4588 {
4589 /* Make sure this buffer isn't wiped out by auto commands. */
4590 ++newbuf->b_locked;
4591
4588 /* set curwin/curbuf to buf and save a few things */ 4592 /* set curwin/curbuf to buf and save a few things */
4589 aucmd_prepbuf(&aco, newbuf); 4593 aucmd_prepbuf(&aco, newbuf);
4590 4594
4591 /* Need to set the filename for autocommands. */ 4595 /* Need to set the filename for autocommands. */
4592 (void)setfname(curbuf, fname, NULL, FALSE); 4596 (void)setfname(curbuf, fname, NULL, FALSE);
4597 /* Remove the "dummy" flag, otherwise autocommands may not 4601 /* Remove the "dummy" flag, otherwise autocommands may not
4598 * work. */ 4602 * work. */
4599 curbuf->b_flags &= ~BF_DUMMY; 4603 curbuf->b_flags &= ~BF_DUMMY;
4600 4604
4601 newbuf_to_wipe.br_buf = NULL; 4605 newbuf_to_wipe.br_buf = NULL;
4602 if (readfile(fname, NULL, 4606 readfile_result = readfile(fname, NULL,
4603 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, 4607 (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
4605 && !got_int 4611 && !got_int
4606 && !(curbuf->b_flags & BF_NEW)) 4612 && !(curbuf->b_flags & BF_NEW))
4607 { 4613 {
4608 failed = FALSE; 4614 failed = FALSE;
4609 if (curbuf != newbuf) 4615 if (curbuf != newbuf)