diff --git a/synctex_parser.c b/synctex_parser.c index e4ac920..d886621 100644 --- a/synctex_parser.c +++ b/synctex_parser.c @@ -899,18 +899,22 @@ SYNCTEX_INLINE static void _synctex_will_free(synctex_node_p node) { * - note: a node is meant to own its child and sibling. * It is not owned by its parent, unless it is its first child. * This destructor is for all nodes with children. + * + * Recursion only occurs from parent to children, which means + * that there is a maximum depth determined by the calling stack size. + * This is not managed. */ static void _synctex_free_node(synctex_node_p node) { - if (node) { + while (node) { + synctex_node_p sibling = __synctex_tree_sibling(node); SYNCTEX_SCANNER_REMOVE_HANDLE_TO(node); SYNCTEX_WILL_FREE(node); - synctex_node_free(__synctex_tree_sibling(node)); synctex_node_free(_synctex_tree_child(node)); _synctex_free(node); + node = sibling; } return; -} -/** +}/** * Free the given handle. * - parameter node: of type synctex_node_p * - note: a node is meant to own its child and sibling.