diff --git a/src/avl.c b/src/avl.c index 4cb198daf..6a428cf24 100644 --- a/src/avl.c +++ b/src/avl.c @@ -205,6 +205,7 @@ void avl_free_nodes(avl_tree_t *avltree) { if(freeitem) freeitem(node->item); free(node); + node = NULL; } avl_clear_tree(avltree); } @@ -218,6 +219,7 @@ void avl_free_nodes(avl_tree_t *avltree) { void avl_free_tree(avl_tree_t *avltree) { avl_free_nodes(avltree); free(avltree); + avltree = NULL; } static void avl_clear_node(avl_node_t *newnode) { @@ -326,6 +328,7 @@ avl_node_t *avl_insert(avl_tree_t *avltree, void *item) { if(avl_insert_node(avltree, newnode)) return newnode; free(newnode); + newnode = NULL; errno = EEXIST; } return NULL; @@ -399,6 +402,7 @@ void *avl_delete_node(avl_tree_t *avltree, avl_node_t *avlnode) { if(avltree->freeitem) avltree->freeitem(item); free(avlnode); + avlnode = NULL; } return item; } diff --git a/src/hv.c b/src/hv.c index a7787b685..6ed4bb5b6 100644 --- a/src/hv.c +++ b/src/hv.c @@ -130,6 +130,7 @@ static dlnode_t * setup_cdllist(double *data, int d, int n) { } free(scratch); + scratch = NULL; for (i = 1; i <= n; i++) avl_init_node(head[i].tnode, head[i].x); @@ -141,12 +142,12 @@ static dlnode_t * setup_cdllist(double *data, int d, int n) { } static void free_cdllist(dlnode_t * head) { - free(head->tnode); /* Frees _all_ nodes. */ - free(head->next); - free(head->prev); - free(head->area); - free(head->vol); - free(head); + free(head->tnode); head->tnode = NULL; + free(head->next); head->next = NULL; + free(head->prev); head->prev = NULL; + free(head->area); head->area = NULL; + free(head->vol); head->vol = NULL; + free(head); head = NULL; } static void delete (dlnode_t *nodep, int dim, double * bound) {