From 5bb323cd3511fb5afd948df634f6b9cb7396e52e Mon Sep 17 00:00:00 2001 From: Jan Sundermeyer Date: Fri, 24 May 2024 19:17:04 +0200 Subject: [PATCH] try fix synctex crash --- src/pdfviewer/synctex/synctex_parser.c | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/pdfviewer/synctex/synctex_parser.c b/src/pdfviewer/synctex/synctex_parser.c index 187cfbe6a7..b7292ed7d1 100644 --- a/src/pdfviewer/synctex/synctex_parser.c +++ b/src/pdfviewer/synctex/synctex_parser.c @@ -900,6 +900,7 @@ SYNCTEX_INLINE static void _synctex_will_free(synctex_node_p node) { * It is not owned by its parent, unless it is its first child. * This destructor is for all nodes with children. */ +/* static void _synctex_free_node(synctex_node_p node) { if (node) { SYNCTEX_SCANNER_REMOVE_HANDLE_TO(node); @@ -910,10 +911,49 @@ static void _synctex_free_node(synctex_node_p node) { nextNode=__synctex_tree_sibling(n); synctex_node_free(_synctex_tree_child(n)); _synctex_free(n); + ++i; } while(n=nextNode); } return; +}*/ + +static void _synctex_free_node(synctex_node_p node) { + if (node) { + SYNCTEX_SCANNER_REMOVE_HANDLE_TO(node); + SYNCTEX_WILL_FREE(node); + + do { + synctex_node_p nextSibling=__synctex_tree_sibling(node); + synctex_node_p n=node; + synctex_node_p nextNode=NULL; + do { + while((nextNode=_synctex_tree_child(n))) { + __synctex_tree_set_child(n, NULL); + n=nextNode; + } + if(n){ + nextNode=__synctex_tree_sibling(n); + if(!nextNode) { + if(n==node){ + _synctex_free(n); + break; + } + nextNode=__synctex_tree_parent(n); + } + _synctex_free(n); + n=nextNode; + } + if(n==node){ + _synctex_free(n); + break; + } + } while(n); + node=nextSibling; + }while(node); + } + return; } + /** * Free the given handle. * - parameter node: of type synctex_node_p @@ -6072,6 +6112,7 @@ synctex_scanner_p synctex_scanner_new_with_output_file(const char * output, cons /* The scanner destructor */ + int synctex_scanner_free(synctex_scanner_p scanner) { int node_count = 0; if (scanner) {