diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-10-19 00:49:29 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-10-19 00:49:29 +0000 |
commit | 95895823f75108cbfed2697498e4e097f493b236 (patch) | |
tree | 77efe89b445f168b7d0c63f3fd5f0a23f6e743e8 /libdimension/kD_splay_tree.c | |
parent | 8710689500d3d35d04aabd727f12698590a816cb (diff) | |
download | dimension-95895823f75108cbfed2697498e4e097f493b236.tar.xz |
Fix some memory leaks.
dmnsn_delete_pigment() was not using the free_fn, and kD splay trees were not
being deleted after raytracing finished.
Diffstat (limited to 'libdimension/kD_splay_tree.c')
-rw-r--r-- | libdimension/kD_splay_tree.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/libdimension/kD_splay_tree.c b/libdimension/kD_splay_tree.c index de70edf..a661602 100644 --- a/libdimension/kD_splay_tree.c +++ b/libdimension/kD_splay_tree.c @@ -29,10 +29,11 @@ dmnsn_kD_splay_tree * dmnsn_new_kD_splay_tree() { dmnsn_kD_splay_tree *tree = malloc(sizeof(dmnsn_kD_splay_tree)); - if (!tree) { + if (tree) { + tree->root = NULL; + } else { dmnsn_error(DMNSN_SEVERITY_HIGH, "kD splay tree allocation failed."); } - tree->root = NULL; return tree; } @@ -67,20 +68,25 @@ dmnsn_kD_splay_copy(dmnsn_kD_splay_tree *tree) /* Recursively free a kD splay tree */ void -dmnsn_delete_kD_splay_tree(dmnsn_kD_splay_tree *tree) +dmnsn_delete_kD_splay_tree_recursive(dmnsn_kD_splay_node *node) { - dmnsn_kD_splay_node *node = tree->root; if (node) { - tree->root = node->contains; - dmnsn_delete_kD_splay_tree(tree); - - tree->root = node->container; - dmnsn_delete_kD_splay_tree(tree); - + dmnsn_delete_kD_splay_tree_recursive(node->contains); + dmnsn_delete_kD_splay_tree_recursive(node->container); dmnsn_delete_kD_splay_node(node); } } +/* Free a kD splay tree */ +void +dmnsn_delete_kD_splay_tree(dmnsn_kD_splay_tree *tree) +{ + if (tree) { + dmnsn_delete_kD_splay_tree_recursive(tree->root); + free(tree); + } +} + /* Return whether node1 contains node2 */ static int dmnsn_box_contains(dmnsn_vector p, dmnsn_vector min, dmnsn_vector max); |