fix(api): nvim_create_buf leaks memory if buffer is loaded early

Problem: memory leak in nvim_create_buf if buflist_new autocommands load the
new buffer early.

Solution: do not open a memfile in that case.
This commit is contained in:
Sean Dewar
2024-03-19 10:55:33 +00:00
parent aca2048bcd
commit d5c23d72a5
2 changed files with 18 additions and 7 deletions

View File

@@ -3135,6 +3135,15 @@ describe('API', function()
-- nowadays this works because we don't execute any spurious autocmds at all #24824
assert_alive()
end)
it('no memory leak when autocommands load the buffer immediately', function()
exec([[
autocmd BufNew * ++once call bufload(expand("<abuf>")->str2nr())
\| let loaded = bufloaded(expand("<abuf>")->str2nr())
]])
api.nvim_create_buf(false, true)
eq(1, eval('g:loaded'))
end)
end)
describe('nvim_get_runtime_file', function()