title: Deleting a whole linked list
body: <p>I am working with linked lists and i fill the structure but when I delete the whole structure and try to print the contents of the linked list (should be null), a list of numbers appear. I know it is probably a memory problem. Any suggestions of how to fix it?</p>
  
  <p>Code for deleting whole linked list:</p>
  
  <pre><code>void destroy(set_elem *head)
  {
      set_elem *current = head;
      set_elem *next;
  
      while (current != NULL)
      {
         next = current-&gt;next;
         free(current);
         current = next;
      }
      head = NULL;
  }
  </code></pre>