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