// Free `p` and all ancestors of `p`.
void free_family(person *p)
{
while (p != NULL)
{
free_family(p->parents[0]);
free_family(p->parents[1]);
free(p);
}
// TODO: Handle base case
// TODO: Free parents
// TODO: Free child
}
I compared my code with others, and found the problem is up here. I think my method is reasonable, but it will lead to segmentation fault. please tell me why.