fix undefined call order in fclose, possible lost output depending on compiler