aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-12-02 10:28:35 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-12-02 10:51:50 +0800
commit47d3d0102fffbfd52b950c521e5d1e443ac7885f (patch)
tree5c3917596a4540730ee7a7017d2f1b64760a2bca /src
parent982c0053f4059fb4558ce83a0b8d250be1058980 (diff)
downloadrneovim-47d3d0102fffbfd52b950c521e5d1e443ac7885f.tar.gz
rneovim-47d3d0102fffbfd52b950c521e5d1e443ac7885f.tar.bz2
rneovim-47d3d0102fffbfd52b950c521e5d1e443ac7885f.zip
vim-patch:8.2.1748: closing split window in other tab may cause a crash
Problem: Closing split window in other tab may cause a crash. Solution: Set tp_curwin properly. (Rob Pilling, closes vim/vim#7018) https://github.com/vim/vim/commit/f3c51bbff1256a52bdd9ede7887f40062be2628c Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/testdir/test_winbuf_close.vim18
-rw-r--r--src/nvim/window.c9
2 files changed, 22 insertions, 5 deletions
diff --git a/src/nvim/testdir/test_winbuf_close.vim b/src/nvim/testdir/test_winbuf_close.vim
index 643c1068bd..26b4ba8778 100644
--- a/src/nvim/testdir/test_winbuf_close.vim
+++ b/src/nvim/testdir/test_winbuf_close.vim
@@ -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
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 80c51516b1..79a90ab8af 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -3058,6 +3058,7 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp)
{
win_T *wp;
+ tabpage_T *win_tp = tp == NULL ? curtab : tp;
if (!win->w_floating) {
// Remove the window and its frame from the tree of frames.
@@ -3082,10 +3083,10 @@ static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp)
}
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;