tree-sitter/haskell-tree-sitter

Interrupting the copy_child_nodes functions can leak memory

robrix opened this issue · 1 comments

Because we’re using -XInterruptibleFFI for ts_node_copy_child_nodes (and ts_tree_cursor_copy_child_nodes, as of #260), the runtime will interrupt the C function by killing the thread. However, these move the cursor, which allocates memory to manage the cursor’s stack; and ts_node_copy_child_nodes allocates a cursor as well.

Thus, any time we interrupt one of these calls, we’re leaking memory, because neither of these functions installs a signal handler to clean up their allocations.

Note that we’ve been doing this for 15 mo (at time of writing), i.e. since 9c28ccf, and this has not been a dramatic issue during that time; but it would still be good to correct.