I have executed following code for free family function -
void free_family(person *p)
{
// TODO: Handle base case
if(p->parents[0] == NULL && p->parents[1] == NULL)
{
free(p);
return;
}
// TODO: Free parent
else
{
for (int i = 0; i < 2; i++)
{
free_family(p->parents[i]);
}
}
// TODO: Free child
}
I have seen the provided answer but I cannot figure out why this code does not work.
valgrind says - total heap usage: 7 allocs, 4 frees, 168 bytes allocated
Please help me .