Skip to content

Commit

Permalink
overwrite freed pointers with NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
mllg committed Apr 8, 2019
1 parent 8a1dd46 commit 9bf80bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/avl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 7 additions & 6 deletions src/hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 9bf80bd

Please sign in to comment.