diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 175f917c2..4ccc5f31d 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -1470,7 +1470,7 @@ void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSe } #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/menu_state_about.cpp b/source/glest_game/menu/menu_state_about.cpp index bc19a36c1..15f913bf3 100644 --- a/source/glest_game/menu/menu_state_about.cpp +++ b/source/glest_game/menu/menu_state_about.cpp @@ -200,7 +200,7 @@ string MenuStateAbout::loadAdditionalCredits(){ std::cout << buffer << std::endl; file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif } return result; diff --git a/source/shared_lib/include/graphics/FileReader.h b/source/shared_lib/include/graphics/FileReader.h index 9a9109876..2b06d7ec1 100644 --- a/source/shared_lib/include/graphics/FileReader.h +++ b/source/shared_lib/include/graphics/FileReader.h @@ -171,14 +171,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con if (ret != NULL) { file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; } } file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return NULL; @@ -223,14 +223,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con if (ret != NULL) { file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; } } file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return NULL; } @@ -368,7 +368,7 @@ T* FileReader::read(const string& filepath) const { T* ret = read(file,filepath); file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; @@ -393,7 +393,7 @@ T* FileReader::read(const string& filepath, T* object) const { T* ret = read(file,filepath,object); file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; diff --git a/source/shared_lib/sources/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp index 637013985..cc9fd7824 100644 --- a/source/shared_lib/sources/map/map_preview.cpp +++ b/source/shared_lib/sources/map/map_preview.cpp @@ -883,7 +883,7 @@ void MapPreview::loadFromFile(const string &path) { } } - fclose(f1); + if(f1) fclose(f1); fileLoaded = true; mapFileLoaded = path; @@ -964,7 +964,7 @@ void MapPreview::saveToFile(const string &path) { } } - fclose(f1); + if(f1) fclose(f1); hasChanged = false; } diff --git a/source/shared_lib/sources/util/leak_dumper.cpp b/source/shared_lib/sources/util/leak_dumper.cpp index 09b9dc55f..54799b21d 100644 --- a/source/shared_lib/sources/util/leak_dumper.cpp +++ b/source/shared_lib/sources/util/leak_dumper.cpp @@ -63,7 +63,7 @@ void AllocRegistry::dump(const char *path) { fprintf(f, "Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes); fprintf(f, "Not monitored allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", nonMonitoredCount, nonMonitoredBytes); - fclose(f); + if(f) fclose(f); printf("Memory leak dump summary at: %s\n",szBuf2); printf("Total leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 254cf2da8..6c5fc99fc 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -376,7 +376,7 @@ void Properties::save(const string &path){ fileStream.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif }