Karsten Hopp e640df
To: vim_dev@googlegroups.com
Karsten Hopp e640df
Subject: Patch 7.4.251
Karsten Hopp e640df
Fcc: outbox
Karsten Hopp e640df
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp e640df
Mime-Version: 1.0
Karsten Hopp e640df
Content-Type: text/plain; charset=UTF-8
Karsten Hopp e640df
Content-Transfer-Encoding: 8bit
Karsten Hopp e640df
------------
Karsten Hopp e640df
Karsten Hopp e640df
Patch 7.4.251
Karsten Hopp e640df
Problem:    Crash when BufAdd autocommand wipes out the buffer.
Karsten Hopp e640df
Solution:   Check for buffer to still be valid. Postpone freeing the buffer
Karsten Hopp e640df
	    structure. (Hirohito Higashi)
Karsten Hopp e640df
Files:	    src/buffer.c, src/ex_cmds.c, src/fileio.c, src/globals.h
Karsten Hopp e640df
Karsten Hopp e640df
Karsten Hopp e640df
*** ../vim-7.4.250/src/buffer.c	2014-03-23 15:12:29.907264336 +0100
Karsten Hopp e640df
--- src/buffer.c	2014-04-06 19:55:53.563350929 +0200
Karsten Hopp e640df
***************
Karsten Hopp e640df
*** 676,683 ****
Karsten Hopp e640df
  #endif
Karsten Hopp e640df
  #ifdef FEAT_AUTOCMD
Karsten Hopp e640df
      aubuflocal_remove(buf);
Karsten Hopp e640df
  #endif
Karsten Hopp e640df
!     vim_free(buf);
Karsten Hopp e640df
  }
Karsten Hopp e640df
  
Karsten Hopp e640df
  /*
Karsten Hopp e640df
--- 676,691 ----
Karsten Hopp e640df
  #endif
Karsten Hopp e640df
  #ifdef FEAT_AUTOCMD
Karsten Hopp e640df
      aubuflocal_remove(buf);
Karsten Hopp e640df
+     if (autocmd_busy)
Karsten Hopp e640df
+     {
Karsten Hopp e640df
+ 	/* Do not free the buffer structure while autocommands are executing,
Karsten Hopp e640df
+ 	 * it's still needed. Free it when autocmd_busy is reset. */
Karsten Hopp e640df
+ 	buf->b_next = au_pending_free_buf;
Karsten Hopp e640df
+ 	au_pending_free_buf = buf;
Karsten Hopp e640df
+     }
Karsten Hopp e640df
+     else
Karsten Hopp e640df
  #endif
Karsten Hopp e640df
! 	vim_free(buf);
Karsten Hopp e640df
  }
Karsten Hopp e640df
  
Karsten Hopp e640df
  /*
Karsten Hopp e640df
***************
Karsten Hopp e640df
*** 1681,1687 ****
Karsten Hopp e640df
--- 1689,1699 ----
Karsten Hopp e640df
  	    buf->b_p_bl = TRUE;
Karsten Hopp e640df
  #ifdef FEAT_AUTOCMD
Karsten Hopp e640df
  	    if (!(flags & BLN_DUMMY))
Karsten Hopp e640df
+ 	    {
Karsten Hopp e640df
  		apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf);
Karsten Hopp e640df
+ 		if (!buf_valid(buf))
Karsten Hopp e640df
+ 		    return NULL;
Karsten Hopp e640df
+ 	    }
Karsten Hopp e640df
  #endif
Karsten Hopp e640df
  	}
Karsten Hopp e640df
  	return buf;
Karsten Hopp e640df
***************
Karsten Hopp e640df
*** 1857,1864 ****
Karsten Hopp e640df
--- 1869,1882 ----
Karsten Hopp e640df
      if (!(flags & BLN_DUMMY))
Karsten Hopp e640df
      {
Karsten Hopp e640df
  	apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf);
Karsten Hopp e640df
+ 	if (!buf_valid(buf))
Karsten Hopp e640df
+ 	    return NULL;
Karsten Hopp e640df
  	if (flags & BLN_LISTED)
Karsten Hopp e640df
+ 	{
Karsten Hopp e640df
  	    apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf);
Karsten Hopp e640df
+ 	    if (!buf_valid(buf))
Karsten Hopp e640df
+ 		return NULL;
Karsten Hopp e640df
+ 	}
Karsten Hopp e640df
  # ifdef FEAT_EVAL
Karsten Hopp e640df
  	if (aborting())		/* autocmds may abort script processing */
Karsten Hopp e640df
  	    return NULL;
Karsten Hopp e640df
*** ../vim-7.4.250/src/ex_cmds.c	2014-04-04 19:00:46.351940169 +0200
Karsten Hopp e640df
--- src/ex_cmds.c	2014-04-06 20:41:37.899356924 +0200
Karsten Hopp e640df
***************
Karsten Hopp e640df
*** 3343,3348 ****
Karsten Hopp e640df
--- 3343,3354 ----
Karsten Hopp e640df
  #endif
Karsten Hopp e640df
  	    buf = buflist_new(ffname, sfname, 0L,
Karsten Hopp e640df
  		    BLN_CURBUF | ((flags & ECMD_SET_HELP) ? 0 : BLN_LISTED));
Karsten Hopp e640df
+ #ifdef FEAT_AUTOCMD
Karsten Hopp e640df
+ 	    /* autocommands may change curwin and curbuf */
Karsten Hopp e640df
+ 	    if (oldwin != NULL)
Karsten Hopp e640df
+ 		oldwin = curwin;
Karsten Hopp e640df
+ 	    old_curbuf = curbuf;
Karsten Hopp e640df
+ #endif
Karsten Hopp e640df
  	}
Karsten Hopp e640df
  	if (buf == NULL)
Karsten Hopp e640df
  	    goto theend;
Karsten Hopp e640df
*** ../vim-7.4.250/src/fileio.c	2014-04-02 14:05:33.999887839 +0200
Karsten Hopp e640df
--- src/fileio.c	2014-04-06 20:34:24.063355976 +0200
Karsten Hopp e640df
***************
Karsten Hopp e640df
*** 9548,9560 ****
Karsten Hopp e640df
  
Karsten Hopp e640df
      /*
Karsten Hopp e640df
       * When stopping to execute autocommands, restore the search patterns and
Karsten Hopp e640df
!      * the redo buffer.
Karsten Hopp e640df
       */
Karsten Hopp e640df
      if (!autocmd_busy)
Karsten Hopp e640df
      {
Karsten Hopp e640df
  	restore_search_patterns();
Karsten Hopp e640df
  	restoreRedobuff();
Karsten Hopp e640df
  	did_filetype = FALSE;
Karsten Hopp e640df
      }
Karsten Hopp e640df
  
Karsten Hopp e640df
      /*
Karsten Hopp e640df
--- 9548,9566 ----
Karsten Hopp e640df
  
Karsten Hopp e640df
      /*
Karsten Hopp e640df
       * When stopping to execute autocommands, restore the search patterns and
Karsten Hopp e640df
!      * the redo buffer.  Free buffers in the au_pending_free_buf list.
Karsten Hopp e640df
       */
Karsten Hopp e640df
      if (!autocmd_busy)
Karsten Hopp e640df
      {
Karsten Hopp e640df
  	restore_search_patterns();
Karsten Hopp e640df
  	restoreRedobuff();
Karsten Hopp e640df
  	did_filetype = FALSE;
Karsten Hopp e640df
+ 	while (au_pending_free_buf != NULL)
Karsten Hopp e640df
+ 	{
Karsten Hopp e640df
+ 	    buf_T *b = au_pending_free_buf->b_next;
Karsten Hopp e640df
+ 	    vim_free(au_pending_free_buf);
Karsten Hopp e640df
+ 	    au_pending_free_buf = b;
Karsten Hopp e640df
+ 	}
Karsten Hopp e640df
      }
Karsten Hopp e640df
  
Karsten Hopp e640df
      /*
Karsten Hopp e640df
*** ../vim-7.4.250/src/globals.h	2014-03-23 15:12:29.943264337 +0100
Karsten Hopp e640df
--- src/globals.h	2014-04-06 20:32:58.339355789 +0200
Karsten Hopp e640df
***************
Karsten Hopp e640df
*** 386,391 ****
Karsten Hopp e640df
--- 386,396 ----
Karsten Hopp e640df
  /* When deleting the current buffer, another one must be loaded.  If we know
Karsten Hopp e640df
   * which one is preferred, au_new_curbuf is set to it */
Karsten Hopp e640df
  EXTERN buf_T	*au_new_curbuf INIT(= NULL);
Karsten Hopp e640df
+ 
Karsten Hopp e640df
+ /* When deleting the buffer and autocmd_busy is TRUE, do not free the buffer
Karsten Hopp e640df
+  * but link it in the list starting with au_pending_free_buf, using b_next.
Karsten Hopp e640df
+  * Free the buffer when autocmd_busy is set to FALSE. */
Karsten Hopp e640df
+ EXTERN buf_T	*au_pending_free_buf INIT(= NULL);
Karsten Hopp e640df
  #endif
Karsten Hopp e640df
  
Karsten Hopp e640df
  #ifdef FEAT_MOUSE
Karsten Hopp e640df
*** ../vim-7.4.250/src/version.c	2014-04-05 21:59:35.939178415 +0200
Karsten Hopp e640df
--- src/version.c	2014-04-06 19:52:46.887350521 +0200
Karsten Hopp e640df
***************
Karsten Hopp e640df
*** 736,737 ****
Karsten Hopp e640df
--- 736,739 ----
Karsten Hopp e640df
  {   /* Add new patch number below this line */
Karsten Hopp e640df
+ /**/
Karsten Hopp e640df
+     251,
Karsten Hopp e640df
  /**/
Karsten Hopp e640df
Karsten Hopp e640df
-- 
Karsten Hopp e640df
hundred-and-one symptoms of being an internet addict:
Karsten Hopp e640df
37. You start looking for hot HTML addresses in public restrooms.
Karsten Hopp e640df
Karsten Hopp e640df
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp e640df
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp e640df
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp e640df
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///