Fixed a bug where we call ferror(...) after calling fclose(...)