From c197d0687cdf9fe369b6aeaa467721bde4b8b36e Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 16 Jun 2012 03:10:38 +0000 Subject: [PATCH] - Fixed: FinalGC() needs to run before the type system is shut down. - Fixed: Don't access class metadata at all in DObject::PropagateMark if the type system is shutdown. - Fixed: If FCompressedMemFile::Reopen() fails, then it would try to double-free memory when deleted. SVN r3688 (trunk) --- src/d_main.cpp | 16 ++++++++++++++++ src/dobject.cpp | 3 ++- src/farchive.cpp | 16 +++++++++++++++- src/sdl/i_main.cpp | 15 --------------- src/win32/i_main.cpp | 16 ---------------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index a44399ff9..0919d3acb 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2054,6 +2054,21 @@ static void CheckCmdLine() } } +//========================================================================== +// +// FinalGC +// +// If this doesn't free everything, the debug CRT will let us know. +// +//========================================================================== + +static void FinalGC() +{ + Args = NULL; + GC::FullGC(); + GC::DelSoftRootHead(); // the soft root head will not be collected by a GC so we have to do it explicitly +} + //========================================================================== // // D_DoomMain @@ -2072,6 +2087,7 @@ void D_DoomMain (void) D_DoomInit(); PClass::StaticInit (); + atterm(FinalGC); // [RH] Make sure zdoom.pk3 is always loaded, // as it contains magic stuff we need. diff --git a/src/dobject.cpp b/src/dobject.cpp index 9f749aeaa..191fa3c43 100644 --- a/src/dobject.cpp +++ b/src/dobject.cpp @@ -453,8 +453,9 @@ size_t DObject::PropagateMark() GC::Mark((DObject **)((BYTE *)this + *offsets)); offsets++; } + return info->Size; } - return info->Size; + return 0; } size_t DObject::PointerSubstitution (DObject *old, DObject *notOld) diff --git a/src/farchive.cpp b/src/farchive.cpp index 9c128e0f7..6b0fafd18 100644 --- a/src/farchive.cpp +++ b/src/farchive.cpp @@ -401,10 +401,13 @@ void FCompressedFile::Explode () uLong newlen; newlen = expandsize; + _heapchk(); r = uncompress (expand, &newlen, m_Buffer + 8, cprlen); if (r != Z_OK || newlen != expandsize) { + _heapchk(); M_Free (expand); + _heapchk(); I_Error ("Could not decompress cfile"); } } @@ -497,7 +500,18 @@ bool FCompressedMemFile::Reopen () m_Mode = EReading; m_Buffer = m_ImplodedBuffer; m_SourceFromMem = true; - Explode (); + try + { + Explode (); + } + catch(...) + { + // If we just leave things as they are, m_Buffer and m_ImplodedBuffer + // both point to the same memory block and both will try to free it. + m_Buffer = NULL; + m_SourceFromMem = false; + throw; + } m_SourceFromMem = false; return true; } diff --git a/src/sdl/i_main.cpp b/src/sdl/i_main.cpp index 5c0bfa506..36cf49617 100644 --- a/src/sdl/i_main.cpp +++ b/src/sdl/i_main.cpp @@ -138,20 +138,6 @@ void STACK_ARGS call_terms () } } -//========================================================================== -// -// FinalGC -// -// Collect garbage one last time before exiting. -// -//========================================================================== - -static void FinalGC() -{ - Args = NULL; - GC::FullGC(); -} - static void STACK_ARGS NewFailure () { I_FatalError ("Failed to allocate memory from system heap"); @@ -323,7 +309,6 @@ int main (int argc, char **argv) try { Args = new DArgs(argc, argv); - atterm(FinalGC); /* killough 1/98: diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 2a65e8c9c..4079fcae7 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -251,21 +251,6 @@ static void UnWTS (void) } } -//========================================================================== -// -// FinalGC -// -// If this doesn't free everything, the debug CRT will let us know. -// -//========================================================================== - -static void FinalGC() -{ - Args = NULL; - GC::FullGC(); - GC::DelSoftRootHead(); // the soft root head will not be collected by a GC so we have to do it explicitly -} - //========================================================================== // // LayoutErrorPane @@ -828,7 +813,6 @@ void DoMain (HINSTANCE hInstance) #endif Args = new DArgs(__argc, __argv); - atterm(FinalGC); // Under XP, get our session ID so we can know when the user changes/locks sessions. // Since we need to remain binary compatible with older versions of Windows, we