--- a/src/tree.c Wed Dec 31 12:51:12 2025 +0100 +++ b/src/tree.c Wed Dec 31 13:39:55 2025 +0100 @@ -458,6 +458,7 @@ ) { CxTreeIterator ret; ret.visit_on_exit = false; + ret.exiting = false; ret.use_dfs = false; ret.loc_children = loc_children; ret.loc_next = loc_next; @@ -568,6 +569,8 @@ } void *cxTreeAddData(CxTree *tree, void *parent, const void *data) { + if (tree->loc_data < 0) return NULL; + void *node = cxZalloc(tree->collection.allocator, tree->node_size); if (node == NULL) return NULL; // LCOV_EXCL_LINE @@ -734,7 +737,7 @@ ) { int result = cxTreeRemoveNode(tree, node, relink_func); if (result == 0) { - cx_invoke_destructor(tree, node); + cx_invoke_destructor_raw(tree, node); return 0; } else { return result; @@ -749,7 +752,8 @@ ); cx_foreach(void *, child, iter) { if (iter.exiting) { - cx_invoke_destructor(tree, child); + // always call the destructors with the node! + cx_invoke_destructor_raw(tree, child); } } tree->collection.size -= iter.counter;