title: Is there anyway to check if there is memory leaks in C?
body: <p>i recently learnt about memalloc() and free() and i was just wondering if there was a way to appropriately check if all the memallocs are appropriately being freed?</p>
  
  <p>I have this code right here for an implementation of doubly linked list, and im unclear whether id need to go through every node and deallocate each p1 and p2, or does doing it once count?:</p>
  
  <pre><code>struct s {
      int data;
      struct s *p1;
      struct s *p2;
  };
  
  void freedl(struct s *p)
  {
      if(p-&gt;p1 != NULL)
      {
          printf("free %d \n", p-&gt;p1-&gt;data);
      }
  
      if(p-&gt;p2 != NULL)
      {
          freedl(p-&gt;p2);
      }
      else
      {
          printf("free last %d", p-&gt;data);
          free(p);
      }
  
  }
  
  int main(void) {
  
      struct s *one, *two, *three, *four, *five, *six;
  
      one = malloc(sizeof *one);
      two = malloc(sizeof *two);
      three = malloc(sizeof *three);
      four = malloc(sizeof *four);
      five = malloc(sizeof *five);
      six = malloc(sizeof *six);
  
      one-&gt;data = 1;
      one-&gt;p1 = NULL;
      one-&gt;p2 = two;
  
      two-&gt;data = 2;
      two-&gt;p1 = one;
      two-&gt;p2 = three;
  
      three-&gt;data = 3;
      three-&gt;p1 = two;
      three-&gt;p2 = four;
  
      four-&gt;data = 4;
      four-&gt;p1 = three;
      four-&gt;p2 = five;
  
      five-&gt;data = 5;
      five-&gt;p1 = four;
      five-&gt;p2 = six;
  
      six-&gt;data = 6;
      six-&gt;p1 = five;
      six-&gt;p2 = NULL;
  
      freedl(one);
  
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>and I'd just like to make sure I'm doing it right!</p>