31422c1
To: vim_dev@googlegroups.com
31422c1
Subject: Patch 7.3.528
31422c1
Fcc: outbox
31422c1
From: Bram Moolenaar <Bram@moolenaar.net>
31422c1
Mime-Version: 1.0
31422c1
Content-Type: text/plain; charset=UTF-8
31422c1
Content-Transfer-Encoding: 8bit
31422c1
------------
31422c1
31422c1
Patch 7.3.528
31422c1
Problem:    Crash when closing last window in a tab. (Alex Efros)
31422c1
Solution:   Use common code in close_last_window_tabpage(). (Christian
31422c1
	    Brabandt)
31422c1
Files:	    src/window.c
31422c1
31422c1
31422c1
*** ../vim-7.3.527/src/window.c	2012-03-16 19:07:54.000000000 +0100
31422c1
--- src/window.c	2012-05-25 12:25:16.000000000 +0200
31422c1
***************
31422c1
*** 23,28 ****
31422c1
--- 23,29 ----
31422c1
  static void win_totop __ARGS((int size, int flags));
31422c1
  static void win_equal_rec __ARGS((win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height));
31422c1
  static int last_window __ARGS((void));
31422c1
+ static int close_last_window_tabpage __ARGS((win_T *win, int free_buf, tabpage_T *prev_curtab));
31422c1
  static win_T *win_free_mem __ARGS((win_T *win, int *dirp, tabpage_T *tp));
31422c1
  static frame_T *win_altframe __ARGS((win_T *win, tabpage_T *tp));
31422c1
  static tabpage_T *alt_tabpage __ARGS((void));
31422c1
***************
31422c1
*** 2105,2110 ****
31422c1
--- 2106,2147 ----
31422c1
  }
31422c1
  
31422c1
  /*
31422c1
+  * Close the possibly last window in a tab page.
31422c1
+  * Returns TRUE when the window was closed already.
31422c1
+  */
31422c1
+     static int
31422c1
+ close_last_window_tabpage(win, free_buf, prev_curtab)
31422c1
+     win_T	*win;
31422c1
+     int		free_buf;
31422c1
+     tabpage_T   *prev_curtab;
31422c1
+ {
31422c1
+     if (firstwin == lastwin)
31422c1
+     {
31422c1
+ 	/*
31422c1
+ 	 * Closing the last window in a tab page.  First go to another tab
31422c1
+ 	 * page and then close the window and the tab page.  This avoids that
31422c1
+ 	 * curwin and curtab are invalid while we are freeing memory, they may
31422c1
+ 	 * be used in GUI events.
31422c1
+ 	 */
31422c1
+ 	goto_tabpage_tp(alt_tabpage());
31422c1
+ 	redraw_tabline = TRUE;
31422c1
+ 
31422c1
+ 	/* Safety check: Autocommands may have closed the window when jumping
31422c1
+ 	 * to the other tab page. */
31422c1
+ 	if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win)
31422c1
+ 	{
31422c1
+ 	    int	    h = tabline_height();
31422c1
+ 
31422c1
+ 	    win_close_othertab(win, free_buf, prev_curtab);
31422c1
+ 	    if (h != tabline_height())
31422c1
+ 		shell_new_rows();
31422c1
+ 	}
31422c1
+ 	return TRUE;
31422c1
+     }
31422c1
+     return FALSE;
31422c1
+ }
31422c1
+ 
31422c1
+ /*
31422c1
   * Close window "win".  Only works for the current tab page.
31422c1
   * If "free_buf" is TRUE related buffer may be unloaded.
31422c1
   *
31422c1
***************
31422c1
*** 2143,2171 ****
31422c1
      }
31422c1
  #endif
31422c1
  
31422c1
!     /*
31422c1
!      * When closing the last window in a tab page first go to another tab
31422c1
!      * page and then close the window and the tab page.  This avoids that
31422c1
!      * curwin and curtab are not invalid while we are freeing memory, they may
31422c1
!      * be used in GUI events.
31422c1
!      */
31422c1
!     if (firstwin == lastwin)
31422c1
!     {
31422c1
! 	goto_tabpage_tp(alt_tabpage());
31422c1
! 	redraw_tabline = TRUE;
31422c1
! 
31422c1
! 	/* Safety check: Autocommands may have closed the window when jumping
31422c1
! 	 * to the other tab page. */
31422c1
! 	if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win)
31422c1
! 	{
31422c1
! 	    int	    h = tabline_height();
31422c1
! 
31422c1
! 	    win_close_othertab(win, free_buf, prev_curtab);
31422c1
! 	    if (h != tabline_height())
31422c1
! 		shell_new_rows();
31422c1
! 	}
31422c1
! 	return;
31422c1
!     }
31422c1
  
31422c1
      /* When closing the help window, try restoring a snapshot after closing
31422c1
       * the window.  Otherwise clear the snapshot, it's now invalid. */
31422c1
--- 2180,2190 ----
31422c1
      }
31422c1
  #endif
31422c1
  
31422c1
!     /* When closing the last window in a tab page first go to another tab page
31422c1
!      * and then close the window and the tab page to avoid that curwin and
31422c1
!      * curtab are invalid while we are freeing memory. */
31422c1
!     if (close_last_window_tabpage(win, free_buf, prev_curtab))
31422c1
!       return;
31422c1
  
31422c1
      /* When closing the help window, try restoring a snapshot after closing
31422c1
       * the window.  Otherwise clear the snapshot, it's now invalid. */
31422c1
***************
31422c1
*** 2225,2231 ****
31422c1
  
31422c1
      /* Autocommands may have closed the window already, or closed the only
31422c1
       * other window or moved to another tab page. */
31422c1
!     if (!win_valid(win) || last_window() || curtab != prev_curtab)
31422c1
  	return;
31422c1
  
31422c1
      /* Free the memory used for the window and get the window that received
31422c1
--- 2244,2251 ----
31422c1
  
31422c1
      /* Autocommands may have closed the window already, or closed the only
31422c1
       * other window or moved to another tab page. */
31422c1
!     if (!win_valid(win) || last_window() || curtab != prev_curtab
31422c1
! 	    || close_last_window_tabpage(win, free_buf, prev_curtab))
31422c1
  	return;
31422c1
  
31422c1
      /* Free the memory used for the window and get the window that received
31422c1
***************
31422c1
*** 2310,2316 ****
31422c1
  
31422c1
  /*
31422c1
   * Close window "win" in tab page "tp", which is not the current tab page.
31422c1
!  * This may be the last window ih that tab page and result in closing the tab,
31422c1
   * thus "tp" may become invalid!
31422c1
   * Caller must check if buffer is hidden and whether the tabline needs to be
31422c1
   * updated.
31422c1
--- 2330,2336 ----
31422c1
  
31422c1
  /*
31422c1
   * Close window "win" in tab page "tp", which is not the current tab page.
31422c1
!  * This may be the last window in that tab page and result in closing the tab,
31422c1
   * thus "tp" may become invalid!
31422c1
   * Caller must check if buffer is hidden and whether the tabline needs to be
31422c1
   * updated.
31422c1
*** ../vim-7.3.527/src/version.c	2012-05-25 11:56:06.000000000 +0200
31422c1
--- src/version.c	2012-05-25 12:38:25.000000000 +0200
31422c1
***************
31422c1
*** 716,717 ****
31422c1
--- 716,719 ----
31422c1
  {   /* Add new patch number below this line */
31422c1
+ /**/
31422c1
+     528,
31422c1
  /**/
31422c1
31422c1
-- 
31422c1
For society, it's probably a good thing that engineers value function over
31422c1
appearance.  For example, you wouldn't want engineers to build nuclear power
31422c1
plants that only _look_ like they would keep all the radiation inside.
31422c1
				(Scott Adams - The Dilbert principle)
31422c1
31422c1
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
31422c1
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
31422c1
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
31422c1
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///