title: Why do I get free(): double free detected in tcache 2 and aborted (core dumped)*
body: <p>I am writing code to get the blood type for each generation. And it has a function, which frees the person and his ancestors, but I got those two errors:
  <em>free(): double free detected in tcache 2;
  Aborted (core dumped)</em>.
  Below is the code to free the family. Any suggestion would be greatly appreciated!</p>
  <blockquote>
  <pre><code>void free_family(person *p)
  {
      // Handle base case: input of NULL
      for (int i = 0; i &lt; 2; i++)
      {
          // do not free NULL pointer
          if (p == NULL)
          {
              continue;
          }
          person *cursor = p -&gt; parents[i];
          person *tmp = cursor;
          while (cursor != NULL)
          {
              //Free parents
              cursor = cursor -&gt; parents[i];
              free(tmp);
              tmp = cursor;
          }
          // Free child
          free(cursor);
          free(p);
      }
  }
  </code></pre>
  </blockquote>