1.1 --- a/src/tree.c Wed Feb 21 18:53:55 2024 +0100 1.2 +++ b/src/tree.c Mon Feb 26 21:07:23 2024 +0100 1.3 @@ -197,7 +197,12 @@ 1.4 void *next; 1.5 cx_tree_iter_search_next: 1.6 // check if there is a sibling 1.7 - next = tree_next(iter->node); 1.8 + if (iter->exiting) { 1.9 + next = iter->next; 1.10 + } else { 1.11 + next = tree_next(iter->node); 1.12 + iter->next = next; 1.13 + } 1.14 if (next == NULL) { 1.15 // no sibling, we are done with this node and exit 1.16 if (iter->visit_on_exit && !iter->exiting) { 1.17 @@ -208,7 +213,7 @@ 1.18 if (iter->depth == 1) { 1.19 // there is no parent - we have iterated the entire tree 1.20 // invalidate the iterator and free the node stack 1.21 - iter->node = NULL; 1.22 + iter->node = iter->next = NULL; 1.23 iter->stack_capacity = iter->depth = 0; 1.24 free(iter->stack); 1.25 iter->stack = NULL;