mirror of
https://github.com/neovim/neovim.git
synced 2026-02-21 18:01:17 +10:00
fix(api): open_win leak from naughty autocommands
Problem: error set by win_set_buf may leak if autocommands immediately close the new window. Solution: free the error set by win_set_buf. (prefer nvim_open_win's error as it's more important and will cause 0 to be returned)
This commit is contained in:
@@ -343,6 +343,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tp) {
|
if (!tp) {
|
||||||
|
api_clear_error(err); // may have been set by win_set_buf
|
||||||
api_set_error(err, kErrorTypeException, "Window was closed immediately");
|
api_set_error(err, kErrorTypeException, "Window was closed immediately");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2068,6 +2068,31 @@ describe('API/win', function()
|
|||||||
api.nvim_open_win(0, true, { split = 'below' })
|
api.nvim_open_win(0, true, { split = 'below' })
|
||||||
eq(11, api.nvim_win_get_height(0))
|
eq(11, api.nvim_win_get_height(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('no leak when win_set_buf fails and window is closed immediately', function()
|
||||||
|
-- Following used to leak.
|
||||||
|
command('autocmd BufEnter * ++once quit! | throw 1337')
|
||||||
|
eq(
|
||||||
|
'Window was closed immediately',
|
||||||
|
pcall_err(
|
||||||
|
api.nvim_open_win,
|
||||||
|
api.nvim_create_buf(true, true),
|
||||||
|
true,
|
||||||
|
{ relative = 'editor', width = 5, height = 5, row = 1, col = 1 }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
-- If the window wasn't closed, still set errors from win_set_buf.
|
||||||
|
command('autocmd BufEnter * ++once throw 1337')
|
||||||
|
eq(
|
||||||
|
'BufEnter Autocommands for "*": 1337',
|
||||||
|
pcall_err(
|
||||||
|
api.nvim_open_win,
|
||||||
|
api.nvim_create_buf(true, true),
|
||||||
|
true,
|
||||||
|
{ relative = 'editor', width = 5, height = 5, row = 1, col = 1 }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('set_config', function()
|
describe('set_config', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user