fix(window): avoid UAF in close_windows (#40853)

(cherry picked from commit a787a31490)
This commit is contained in:
Barrett Ruth
2026-07-20 02:48:36 -05:00
committed by github-actions[bot]
parent 6cb9334aa0
commit 37d7b11bc1
2 changed files with 15 additions and 1 deletions

View File

@@ -2632,7 +2632,7 @@ void close_windows(buf_T *buf, bool keep_curwin)
}
if (!win_close_othertab(wp, false, tp, false)) {
// If closing the window fails give up, to avoid looping forever.
break;
goto theend;
}
// Start all over, the tab page may be closed and

View File

@@ -2461,6 +2461,20 @@ describe('api/buf', function()
ok(not api.nvim_buf_is_loaded(b))
ok(api.nvim_buf_is_valid(b))
end)
it('does not crash if WinClosed closes the next tabpage #40852', function()
exec_lua(function()
vim.cmd.tabnew()
vim.api.nvim_create_autocmd('WinClosed', {
callback = function()
pcall(vim.api.nvim_win_close, 0, true)
end,
})
local bufs = vim.api.nvim_list_bufs()
vim.api.nvim_buf_delete(bufs[#bufs - 1], { force = true })
end)
assert_alive()
end)
end)
describe('nvim_buf_get_mark', function()