From 112800cb985a964b698d934520d3c2e5b8bcd378 Mon Sep 17 00:00:00 2001 From: "gregory.hainaut@gmail.com" Date: Fri, 20 Aug 2010 11:13:40 +0000 Subject: [PATCH] common, GSnull, zzogl-pg, SPU2null: add more safety to some fclose functions. Avoid a bunch of double free and memory corruption. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3671 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/include/PS2Eext.h | 10 ++++++++-- plugins/GSnull/GS.cpp | 10 ++++++++-- plugins/SPU2null/SPU2.cpp | 10 ++++++++-- plugins/zzogl-pg/opengl/ZZLog.cpp | 7 +++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/common/include/PS2Eext.h b/common/include/PS2Eext.h index f23be0022a..34a9d70b8d 100644 --- a/common/include/PS2Eext.h +++ b/common/include/PS2Eext.h @@ -64,7 +64,10 @@ struct PluginLog void Close() { - if (LogFile) fclose(LogFile); + if (LogFile) { + fclose(LogFile); + LogFile = NULL; + } } void Write(const char *fmt, ...) @@ -132,7 +135,10 @@ struct PluginConf void Close() { - fclose(ConfFile); + if (ConfFile) { + fclose(ConfFile); + ConfFile = NULL; + } } int ReadInt(const std::string& item, int defval) diff --git a/plugins/GSnull/GS.cpp b/plugins/GSnull/GS.cpp index 3b6ffe2cc7..52327e4ef7 100644 --- a/plugins/GSnull/GS.cpp +++ b/plugins/GSnull/GS.cpp @@ -136,7 +136,10 @@ EXPORT_C_(void) GSsetLogDir(const char* dir) s_strLogPath = (dir==NULL) ? "logs/" : dir; // Reload the log file after updated the path - if (gsLog != NULL) fclose(gsLog); + if (gsLog) { + fclose(gsLog); + gsLog = NULL; + } OpenLog(); } @@ -156,7 +159,10 @@ EXPORT_C_(void) GSshutdown() GSCloseWindow(); #ifdef GS_LOG - if (gsLog) fclose(gsLog); + if (gsLog) { + fclose(gsLog); + gsLog = NULL; + } #endif } diff --git a/plugins/SPU2null/SPU2.cpp b/plugins/SPU2null/SPU2.cpp index 4fe2da3b62..73cda72ef0 100644 --- a/plugins/SPU2null/SPU2.cpp +++ b/plugins/SPU2null/SPU2.cpp @@ -141,7 +141,10 @@ EXPORT_C_(void) SPU2setLogDir(const char* dir) s_strLogPath = (dir==NULL) ? "logs/" : dir; // Reload the log file after updated the path - if (spu2Log) fclose(spu2Log); + if(spu2Log) { + fclose(spu2Log); + spu2Log = NULL; + } OpenLog(); } @@ -209,7 +212,10 @@ EXPORT_C_(void) SPU2shutdown() free(spu2mem); spu2mem = NULL; #ifdef SPU2_LOG - if (spu2Log) fclose(spu2Log); + if(spu2Log) { + fclose(spu2Log); + spu2Log = NULL; + } #endif } diff --git a/plugins/zzogl-pg/opengl/ZZLog.cpp b/plugins/zzogl-pg/opengl/ZZLog.cpp index ae2869b4c4..6ad727a9c5 100644 --- a/plugins/zzogl-pg/opengl/ZZLog.cpp +++ b/plugins/zzogl-pg/opengl/ZZLog.cpp @@ -53,7 +53,10 @@ bool Open() void Close() { - if (gsLog != NULL) fclose(gsLog); + if (gsLog != NULL) { + fclose(gsLog); + gsLog = NULL; + } } void SetDir(const char* dir) @@ -62,7 +65,7 @@ void SetDir(const char* dir) s_strLogPath = (dir==NULL) ? "logs/" : dir; // Reload the log file after updated the path - if (gsLog != NULL) fclose(gsLog); + Close(); Open(); }