@@ -365,20 +365,20 @@ cdef int free_tree(Tree* tree) nogil:
365
365
for i in range (3 ):
366
366
cnt[i] = 0
367
367
free_recursive(tree, tree.root_node, cnt)
368
- if not tree.root_node.is_leaf:
369
- free(tree.root_node.children)
370
- free(tree.root_node.width)
371
- free(tree.root_node.left_edge)
372
- free(tree.root_node.center)
373
- free(tree.root_node.barycenter)
374
- free(tree.root_node.leaf_point_position)
375
- free(tree.root_node)
376
368
check = cnt[0 ] == tree.n_cells
377
369
check &= cnt[2 ] == tree.n_points
378
370
free(tree)
379
371
free(cnt)
380
372
return check
381
373
374
+ cdef void free_post_children(Node * node) nogil:
375
+ free(node.width)
376
+ free(node.left_edge)
377
+ free(node.center)
378
+ free(node.barycenter)
379
+ free(node.leaf_point_position)
380
+ free(node)
381
+
382
382
cdef void free_recursive(Tree* tree, Node * root, long * counts) nogil:
383
383
# Free up all of the tree nodes recursively
384
384
# while counting the number of nodes visited
@@ -396,13 +396,14 @@ cdef void free_recursive(Tree* tree, Node *root, long* counts) nogil:
396
396
counts[2 ] += 1
397
397
else :
398
398
free(child.children)
399
- free(child.width)
400
- free(child.left_edge)
401
- free(child.center)
402
- free(child.barycenter)
403
- free(child.leaf_point_position)
404
- free(child)
405
399
400
+ free_post_children(child)
401
+
402
+ if root == tree.root_node:
403
+ if not root.is_leaf:
404
+ free(root.children)
405
+
406
+ free_post_children(root)
406
407
407
408
cdef long count_points(Node* root, long count) nogil:
408
409
# Walk through the whole tree and count the number
0 commit comments