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