]> granicus.if.org Git - vim/commitdiff
patch 8.2.1748: closing split window in other tab may cause a crash v8.2.1748
authorBram Moolenaar <Bram@vim.org>
Sat, 26 Sep 2020 17:11:39 +0000 (19:11 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 26 Sep 2020 17:11:39 +0000 (19:11 +0200)
Problem:    Closing split window in other tab may cause a crash.
Solution:   Set tp_curwin properly. (Rob Pilling, closes #7018)

src/testdir/test_winbuf_close.vim
src/version.c
src/window.c

index 1d3e35708e405ef581939d826f53e60847957452..2530be063573c7e03edb99df7d68d2b0f5fc8558 100644 (file)
@@ -192,7 +192,23 @@ func Test_tabwin_close()
   call win_execute(l:wid, 'close')
   " Should not crash.
   call assert_true(v:true)
-  %bwipe!
+
+  " This tests closing a window in another tab, while leaving the tab open
+  " i.e. two windows in another tab.
+  tabedit
+  let w:this_win = 42
+  new
+  let othertab_wid = win_getid()
+  tabprevious
+  call win_execute(othertab_wid, 'q')
+  " drawing the tabline helps check that the other tab's windows and buffers
+  " are still valid
+  redrawtabline
+  " but to be certain, ensure we can focus the other tab too
+  tabnext
+  call assert_equal(42, w:this_win)
+
+  bwipe!
 endfunc
 
 " Test when closing a split window (above/below) restores space to the window
index 03765bf1b349085c50a5e7851f7b69167af47a38..c253d09cf5ff26a9e243809857f24be5b57ca31b 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1748,
 /**/
     1747,
 /**/
index 75e049562be527e75430014d0e73e1ef67422168..c73062ddd6f7d700dabbb72de91e538db249b88c 100644 (file)
@@ -2745,6 +2745,7 @@ win_free_mem(
 {
     frame_T    *frp;
     win_T      *wp;
+    tabpage_T  *win_tp = tp == NULL ? curtab : tp;
 
     // Remove the window and its frame from the tree of frames.
     frp = win->w_frame;
@@ -2752,10 +2753,10 @@ win_free_mem(
     vim_free(frp);
     win_free(win, tp);
 
-    // When deleting the current window of another tab page select a new
-    // current window.
-    if (tp != NULL && win == tp->tp_curwin)
-       tp->tp_curwin = wp;
+    // When deleting the current window in the tab, select a new current
+    // window.
+    if (win == win_tp->tp_curwin)
+       win_tp->tp_curwin = wp;
 
     return wp;
 }