-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
fix(api): on_detach consistently before buf_freeall autocmds #34024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fd4d829
to
5ba2d12
Compare
5ba2d12
to
e0a9f39
Compare
e0a9f39
to
614a159
Compare
src/nvim/buffer.c
Outdated
// Disable buffer-updates for the current buffer. | ||
buf_updates_unload(buf, false); | ||
if (!bufref_valid(&bufref)) { | ||
// on_detach callback deleted the buffer. | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on_detach
has textlock set, and like the autocmds below has b_locked
set here too. Makes it pretty hard to delete the buffer, but it might still be possible; it's at least consistent with below to include the check.
2bc7e43
to
8b7feb8
Compare
Problem: on_detach may be called after buf_freeall and other important things, plus its textlock restrictions are insufficient. This can cause issues such as leaks, internal errors and crashes. Solution: disable buffer updates in buf_freeall, before autocommands (like the order after neovim#35355 and when do_ecmd reloads a buffer). Don't do so in free_buffer_stuff; it's not safe to run user code there, and buf_freeall already runs before then; just free them to avoid leaks if buf_freeall autocommands registered more for some reason. Fixes neovim#28084 Fixes neovim#33967 Fixes neovim#35116
8b7feb8
to
9a47ec9
Compare
end) | ||
|
||
describe('nvim_buf_attach on_detach', function() | ||
it('is invoked before unloading buffer', function() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My test supersedes this one, so I've removed it (but kept the case when wiping the last listed non-reusable buffer)
Successfully created backport PR for |
Problem: on_detach may be called after buf_freeall and other important
things, plus its textlock restrictions are insufficient. This can cause issues
such as leaks, internal errors and crashes.
Solution: disable buffer updates in buf_freeall, before autocommands (like the
order after #35355 and when do_ecmd reloads a buffer). Don't do so in
free_buffer_stuff; it's not safe to run user code there, and buf_freeall already
runs before then; just free them to avoid leaks if buf_freeall autocommands
registered more for some reason.
Fixes #28084
Fixes #33967
Fixes #35116