I implemented the tree data structure for pset6. It's all doing it right. On checking with valgrind it is even freeing the memory. The valgrind shows that all the blocks were freed. But the error summary is as follows

ERROR SUMMARY: 9912829 errors from 9 contexts (suppressed: 0 from 0)

Probably the cause of the errors is in my freenode function which I implemented the code for my freenode function called by bool unload() is as follows. Please solve my problem.

* Frees  all the node
void freenode(node* unloader)
    for (int i = 0; i < 27; i++)
        if (unloader -> children[i] != NULL)

    if (unloader != NULL)

The cause told by valgrind is

Conditional jump or move depends on uninitialised value(s)

Please solve my problem.

2 Answers 2


The cause you have pasted means that you are checking the value of a variable you didn't previously specify (most likely unloader -> children[i] != NULL). When creating a new node, you should initialize all children node pointers to NULL to make sure they don't contain any uninitialized, "garbage" memory.

  • It is initialized to root in the unload function. This isn't the problem. Commented Jun 25, 2014 at 11:04
  • @AbdulHannanAli But your children are not. You probably have the children as a member of your node, uninitialized. And I am talking about all the children of all the nodes, not specifically the root one.
    – skreborn
    Commented Jun 25, 2014 at 11:07
  • my errors size reduced from a thousands to hundreds by setting the initial value of all children to NULL in load but still I have to figure why are the 200 coming now. Commented Jun 25, 2014 at 11:46
  • @AbdulHannanAli Well, in that case, you could try Kareem's suggestion on using the --track-origins=yes flag to see where the problem originates from.
    – skreborn
    Commented Jun 25, 2014 at 12:07
  • Thanks skreborn you really helped me. After hours of struggling I was able to debug my program. Thanks alot. Commented Jun 25, 2014 at 14:20

When implementing a recursive function, the base case should be written first because it's the first thing that should be executed to determine whether there should be one more recursive call or not!

What you're doing, basically, is that you're executing the loop no matter whether the base case is reached and that's a bad practice and might sometimes cause some errors.

You may compile your program with the -ggdb3 flag and execute valgrind with the flag --leak-check=full. This will give you information about what and where exactly valgrind thinks the errors are in your code.

clang -ggdb3 prog.c -o prog
valgrind --leak-check=full ./prog

Update: for your error, you may check also use the --track-origins=yes to track the origin of uninitialized values as this answer suggests!

  • But Is there any base case for void function? I implemented it but it gives me an error. Commented Jun 25, 2014 at 11:02
  • 1
    Yes, surely there is! You may use return; to end the execution of a void function immediately!
    – kzidane
    Commented Jun 25, 2014 at 11:04
  • Thanks Kareem Mesbah your answer was really helpful in debugging process. Kareem you are a super man. Commented Jun 25, 2014 at 14:21

You must log in to answer this question.

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