fclose() then free()?

free is called in response to malloc to return allocated memory. fopen likely indeed does do some mallocing, but the act of closing the handle (fclose) is, by design, going to clean up everything fopen did. The contract you have with fopen is that closing the handle will free all outstanding resources.

The general rule of thumb is for every alloc have a free. If you call a function which does an alloc, it's description should warn you of what the caller is responsible for freeing.

Long story short, fclose will clean up any resources created by fopen.


Memory allocation of the fopen function is implementation dependent (per CRT). You can be sure that fclose is always implemented to free all the memory that fopen allocated.