fix(treesitter): fix another TSNode:tree() double free

Unfortunately the gc=false objects can refer to a dangling tree if the
gc=true tree was freed first. This reuses the same tree object as the
node itself is keeping alive via the uservalue of the node userdata.
(wrapped in a table due to lua 5.1 restrictions)
This commit is contained in:
bfredl
2023-08-29 11:21:57 +02:00
committed by Christian Clason
parent a3c963adfc
commit 32de3f98ed
2 changed files with 25 additions and 11 deletions

View File

@@ -26,6 +26,20 @@ describe('treesitter node API', function()
assert_alive()
end)
it('double free tree 2', function()
exec_lua([[
parser = vim.treesitter.get_parser(0, "c")
local x = parser:parse()[1]:root():tree()
vim.api.nvim_buf_set_text(0, 0,0, 0,0, {'y'})
parser:parse()
vim.api.nvim_buf_set_text(0, 0,0, 0,1, {'z'})
parser:parse()
collectgarbage()
x:root()
]])
assert_alive()
end)
it('can move between siblings', function()
insert([[
int main(int x, int y, int z) {