Before the lifetime of the last pointer object that stores the return value of a call to the fopen() or freopen() function has ended, the fclose() function must be called with that pointer value.
In general, this rule can also be applied to other functions with open and close resources, such as the POSIX open() and close() functions.
...