mirror of
https://github.com/neovim/neovim.git
synced 2025-12-08 23:52:39 +00:00
fix(win): ignore closing wins in win_findbuf #12798
This caused segfaults when calling win_findbuf in an `on_detach` callback, when the callback was triggered when closing the last window containing the buffer.
This commit is contained in:
@@ -6986,7 +6986,7 @@ void win_findbuf(typval_T *argvars, list_T *list)
|
||||
int bufnr = tv_get_number(&argvars[0]);
|
||||
|
||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||
if (wp->w_buffer->b_fnum == bufnr) {
|
||||
if (!wp->w_closing && wp->w_buffer->b_fnum == bufnr) {
|
||||
tv_list_append_number(list, wp->handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,4 +216,23 @@ describe('lua: buffer event callbacks', function()
|
||||
eq(1, meths.get_var('listener_cursor_line'))
|
||||
end)
|
||||
|
||||
it('does not SEGFAULT when calling win_findbuf in on_detach', function()
|
||||
|
||||
exec_lua[[
|
||||
local buf = vim.api.nvim_create_buf(false, false)
|
||||
|
||||
vim.cmd"split"
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
|
||||
vim.api.nvim_buf_attach(buf, false, {
|
||||
on_detach = function(_, buf)
|
||||
vim.fn.win_findbuf(buf)
|
||||
end
|
||||
})
|
||||
]]
|
||||
|
||||
command("q!")
|
||||
helpers.assert_alive()
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user