fix(window): crash closing only non-float if autocmds :tabonly (#37218)

Problem: null pointer member access when closing the only non-float in the
current tab page if autocommands after closing all floats also close all other
tab pages. (making it the last window)

Solution: check last_window again after closing the floats.

Also reduce the scope of "wp"; it would be bugprone to use it before it's later
reassigned to the rv of win_free_mem if freed by Buf/WinLeave.
This commit is contained in:
Sean Dewar
2026-01-04 13:15:08 +00:00
committed by GitHub
parent 5af11b3bbf
commit c14de47f1a
2 changed files with 16 additions and 4 deletions

View File

@@ -524,6 +524,11 @@ describe('float window', function()
it('if called from non-floating window', function()
api.nvim_set_current_win(old_win)
eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
-- Start with many tab pages, but make autocommands from closing floats leave us with just
-- one (where we're now the last window).
command('tabnew | autocmd WinClosed * ++once tabonly')
api.nvim_open_win(0, false, float_opts)
eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, 0, true))
end)
it('if called from floating window', function()
eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))