Shouldn't it be _fcloseall? and not fcloseall?

You can check the return value of fclose to see if the file was really closed.
I'd add the tracing to see in the log that the actual number of fopen calls is equal to fclose calls...

You can miss some place where fclose is called on some condition, and otherwise the file is left opened...