3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.320
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.320
3ef2ca
Problem:    Possible crash when an BufLeave autocommand deletes the buffer.
3ef2ca
Solution:   Check for the window pointer being valid.  Postpone freeing the
3ef2ca
	    window until autocommands are done. (Yasuhiro Matsumoto)
3ef2ca
Files:	    src/buffer.c, src/fileio.c, src/globals.h, src/window.c
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.319/src/buffer.c	2014-05-07 16:35:05.029152844 +0200
3ef2ca
--- src/buffer.c	2014-06-12 13:47:17.799737639 +0200
3ef2ca
***************
3ef2ca
*** 371,377 ****
3ef2ca
  	unload_buf = TRUE;
3ef2ca
  #endif
3ef2ca
  
3ef2ca
!     if (win != NULL)
3ef2ca
      {
3ef2ca
  	/* Set b_last_cursor when closing the last window for the buffer.
3ef2ca
  	 * Remember the last cursor position and window options of the buffer.
3ef2ca
--- 371,381 ----
3ef2ca
  	unload_buf = TRUE;
3ef2ca
  #endif
3ef2ca
  
3ef2ca
!     if (win != NULL
3ef2ca
! #ifdef FEAT_WINDOWS
3ef2ca
! 	&& win_valid(win)	/* in case autocommands closed the window */
3ef2ca
! #endif
3ef2ca
! 	    )
3ef2ca
      {
3ef2ca
  	/* Set b_last_cursor when closing the last window for the buffer.
3ef2ca
  	 * Remember the last cursor position and window options of the buffer.
3ef2ca
*** ../vim-7.4.319/src/fileio.c	2014-05-02 15:46:10.731268318 +0200
3ef2ca
--- src/fileio.c	2014-06-12 13:53:33.207751842 +0200
3ef2ca
***************
3ef2ca
*** 9549,9555 ****
3ef2ca
  
3ef2ca
      /*
3ef2ca
       * When stopping to execute autocommands, restore the search patterns and
3ef2ca
!      * the redo buffer.  Free buffers in the au_pending_free_buf list.
3ef2ca
       */
3ef2ca
      if (!autocmd_busy)
3ef2ca
      {
3ef2ca
--- 9549,9556 ----
3ef2ca
  
3ef2ca
      /*
3ef2ca
       * When stopping to execute autocommands, restore the search patterns and
3ef2ca
!      * the redo buffer.  Free any buffers in the au_pending_free_buf list and
3ef2ca
!      * free any windows in the au_pending_free_win list.
3ef2ca
       */
3ef2ca
      if (!autocmd_busy)
3ef2ca
      {
3ef2ca
***************
3ef2ca
*** 9562,9567 ****
3ef2ca
--- 9563,9574 ----
3ef2ca
  	    vim_free(au_pending_free_buf);
3ef2ca
  	    au_pending_free_buf = b;
3ef2ca
  	}
3ef2ca
+ 	while (au_pending_free_win != NULL)
3ef2ca
+ 	{
3ef2ca
+ 	    win_T *w = au_pending_free_win->w_next;
3ef2ca
+ 	    vim_free(au_pending_free_win);
3ef2ca
+ 	    au_pending_free_win = w;
3ef2ca
+ 	}
3ef2ca
      }
3ef2ca
  
3ef2ca
      /*
3ef2ca
*** ../vim-7.4.319/src/globals.h	2014-05-28 18:22:37.876225054 +0200
3ef2ca
--- src/globals.h	2014-06-12 13:54:29.163753959 +0200
3ef2ca
***************
3ef2ca
*** 387,396 ****
3ef2ca
   * which one is preferred, au_new_curbuf is set to it */
3ef2ca
  EXTERN buf_T	*au_new_curbuf INIT(= NULL);
3ef2ca
  
3ef2ca
! /* When deleting the buffer and autocmd_busy is TRUE, do not free the buffer
3ef2ca
!  * but link it in the list starting with au_pending_free_buf, using b_next.
3ef2ca
!  * Free the buffer when autocmd_busy is set to FALSE. */
3ef2ca
  EXTERN buf_T	*au_pending_free_buf INIT(= NULL);
3ef2ca
  #endif
3ef2ca
  
3ef2ca
  #ifdef FEAT_MOUSE
3ef2ca
--- 387,398 ----
3ef2ca
   * which one is preferred, au_new_curbuf is set to it */
3ef2ca
  EXTERN buf_T	*au_new_curbuf INIT(= NULL);
3ef2ca
  
3ef2ca
! /* When deleting a buffer/window and autocmd_busy is TRUE, do not free the
3ef2ca
!  * buffer/window. but link it in the list starting with
3ef2ca
!  * au_pending_free_buf/ap_pending_free_win, using b_next/w_next.
3ef2ca
!  * Free the buffer/window when autocmd_busy is being set to FALSE. */
3ef2ca
  EXTERN buf_T	*au_pending_free_buf INIT(= NULL);
3ef2ca
+ EXTERN win_T	*au_pending_free_win INIT(= NULL);
3ef2ca
  #endif
3ef2ca
  
3ef2ca
  #ifdef FEAT_MOUSE
3ef2ca
*** ../vim-7.4.319/src/window.c	2014-06-12 11:49:42.219470717 +0200
3ef2ca
--- src/window.c	2014-06-12 13:51:54.939748124 +0200
3ef2ca
***************
3ef2ca
*** 4597,4603 ****
3ef2ca
      if (wp != aucmd_win)
3ef2ca
  #endif
3ef2ca
  	win_remove(wp, tp);
3ef2ca
!     vim_free(wp);
3ef2ca
  
3ef2ca
  #ifdef FEAT_AUTOCMD
3ef2ca
      unblock_autocmds();
3ef2ca
--- 4597,4609 ----
3ef2ca
      if (wp != aucmd_win)
3ef2ca
  #endif
3ef2ca
  	win_remove(wp, tp);
3ef2ca
!     if (autocmd_busy)
3ef2ca
!     {
3ef2ca
! 	wp->w_next = au_pending_free_win;
3ef2ca
! 	au_pending_free_win = wp;
3ef2ca
!     }
3ef2ca
!     else
3ef2ca
! 	vim_free(wp);
3ef2ca
  
3ef2ca
  #ifdef FEAT_AUTOCMD
3ef2ca
      unblock_autocmds();
3ef2ca
*** ../vim-7.4.319/src/version.c	2014-06-12 13:28:26.771694851 +0200
3ef2ca
--- src/version.c	2014-06-12 13:40:23.507721966 +0200
3ef2ca
***************
3ef2ca
*** 736,737 ****
3ef2ca
--- 736,739 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     320,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
Life would be so much easier if we could just look at the source code.
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///