Blame SOURCES/7.4.320

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