jlaurens / synctex

Synchronization for TeX
MIT License
57 stars 19 forks source link

scanner_free crashes with special file on windows #85

Closed sunderme closed 3 weeks ago

sunderme commented 1 month ago

This is a different file than used in #64 Issue in txs: https://github.com/texstudio-org/texstudio/issues/3672 (files are given here)

My solution:

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;
}