From 50a03c0e9975925e3198a2741c5b9fc0ad727e84 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 29 Aug 2023 11:21:57 +0200 Subject: 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) --- test/functional/treesitter/node_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional') diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index 72508ba958..eef75d0e91 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -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) { -- cgit