From 2cd4229d01df4176527e8e8a04eb82abcfa7e2a1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Aug 2026 20:13:08 +0800 Subject: [PATCH] fix(window): crash when closing new curwin during CTRL-W_x (#41378) Problem: Crash when closing the new current window during CTRL-W_x. Solution: Remove a duplicate redraw of a window that should normally be already mark for redraw in the previous call. --- src/nvim/window.c | 1 - test/functional/autocmd/autocmd_spec.lua | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/nvim/window.c b/src/nvim/window.c index c1b137890a..efa984f1a6 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1950,7 +1950,6 @@ static void win_exchange(int Prenum) win_enter(wp, true); redraw_later(curwin, UPD_NOT_VALID); - redraw_later(wp, UPD_NOT_VALID); } // rotate windows: if upwards true the second window becomes the first one diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 6fb96331a6..5172d771e1 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -741,6 +741,18 @@ describe('autocmd', function() eq('flarb', fn.bufname()) end) + it('no use-after-free when closing new curwin during CTRL-W_x #41373', function() + exec([[ + tabnew + vsplit + autocmd WinLeave * ++once bwipe! + ]]) + eq(2, #api.nvim_list_tabpages()) + feed('x') + eq(1, #api.nvim_list_tabpages()) + assert_alive() + end) + it('does not ignore comma-separated patterns after a buffer-local pattern', function() exec [[ edit baz " reuses buffer 1