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
This commit is contained in:
gregory.hainaut@gmail.com 2010-08-20 11:13:40 +00:00
parent 92dbee7e79
commit 112800cb98
4 changed files with 29 additions and 8 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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();
}