From d5c23d72a5e4d2abb0903e58c4953fa0303d4ad6 Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:55:33 +0000 Subject: 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. --- test/functional/api/vim_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 09a45242ec..a3f70efcea 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -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("")->str2nr()) + \| let loaded = bufloaded(expand("")->str2nr()) + ]]) + api.nvim_create_buf(false, true) + eq(1, eval('g:loaded')) + end) end) describe('nvim_get_runtime_file', function() -- cgit