0

It looks like my unload function is not working properly. Valgrind shows 0 errors, but when I print out the address of my root node, it is not NULL. Hence my unload function (which returns true if root == NULL) does not return true.

If I try to manually free the root node, I get an invalid free error instead: Address 0x51fc2c0 is 0 bytes inside a block of size 224 free'd.

I have implemented my root node as a node* and not a separate struct, if that matters.

Does anyone know what I did wrong? If you need any more info to help troubleshoot the problem, please let me know.

EDIT: Ok so I realised that after you free the nodes, the addresses are still there (correct me if I'm wrong), so I'll have to figure out some other way for my unload function to return true.

0

My function had actually correctly freed all nodes (that's why valgrind returned 0 errors). However, my implementation of unload was flawed in that I tried to check if root was freed with if (root == NULL), which was wrong. Because of this, unload returned false when it in fact correctly freed all memory.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .