Freeing allocated memory: am I missing something? If this question should be on stackoverflow instead, please point it out. I'll put it up there.

 struct {
      FILE * fd;
      hdr_t file_header;
      body_t file_body;
 } fileinfo;


The above is an approximate recreation of a structure that I have in my code. There is a separate function we use for thread cleanup. A pointer to the above structure is a parameter to this function. 

 void cleanup(void * args) 
 {
      struct fileinfo *file_ptr = (struct fileinfo *) args;

      if(file_ptr-&gt;fd &gt; 0)
      {
           fclose(file_ptr-&gt;fd);
      }
      free(file_ptr);
  }


Does the free() - as called above - actually free all the memory allocated to file_ptr? Should there not be a free for the hdr_t and body_t as well?
The basic logic is that you only free dynamically allocated resources. Those that were created with malloc.

Hdr_t and body_t are automatically allocated and must therefore not be freed.

The most important point is that you might under no circumstances free a pointer without checking if it is not pointing to 0.

This following fragment will core:

void * ptr = 0;
free (ptr);


Therefore always do something like this:

if (ptr != 0)
    free(ptr)