nodes_count function is called any time I "free" mallocated nodes of the tree and it accesses "freed" memory(it's not NULL) when I do a NULL check:
Code:
#define CHILDREN_COUNT aLot
typedef struct node {
node_info value;
struct node * children[CHILDREN_COUNT];
} node;
// folowing functions are recursive
add_node(node * node_, ...);
free_nodes(node * node_, ...); // follows to the end of branch and starts to call free(node *), but it doesn't actually free memory
nodes_count(node * node_, ...) {
...
if(*(node_->children + index) == NULL) {
return;
}
...*(node_->children + index)... // accesses "freed" node_
...
}
int main() {
...
node tree[CHILDREN_COUNT];
add_node(tree + index, ...);
free_nodes(tree, ...);
nodes_count(tree, ...); // segfaults by accessing freed memory
...
}
count is needed.
What kind of check should I perform or what is a way around this ?
Thanks.