- 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)
This commit is contained in:
Randy Heit 2012-06-16 03:10:38 +00:00
parent 970d5afcd2
commit c197d0687c
5 changed files with 33 additions and 33 deletions

View File

@ -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 // D_DoomMain
@ -2072,6 +2087,7 @@ void D_DoomMain (void)
D_DoomInit(); D_DoomInit();
PClass::StaticInit (); PClass::StaticInit ();
atterm(FinalGC);
// [RH] Make sure zdoom.pk3 is always loaded, // [RH] Make sure zdoom.pk3 is always loaded,
// as it contains magic stuff we need. // as it contains magic stuff we need.

View File

@ -453,9 +453,10 @@ size_t DObject::PropagateMark()
GC::Mark((DObject **)((BYTE *)this + *offsets)); GC::Mark((DObject **)((BYTE *)this + *offsets));
offsets++; offsets++;
} }
}
return info->Size; return info->Size;
} }
return 0;
}
size_t DObject::PointerSubstitution (DObject *old, DObject *notOld) size_t DObject::PointerSubstitution (DObject *old, DObject *notOld)
{ {

View File

@ -401,10 +401,13 @@ void FCompressedFile::Explode ()
uLong newlen; uLong newlen;
newlen = expandsize; newlen = expandsize;
_heapchk();
r = uncompress (expand, &newlen, m_Buffer + 8, cprlen); r = uncompress (expand, &newlen, m_Buffer + 8, cprlen);
if (r != Z_OK || newlen != expandsize) if (r != Z_OK || newlen != expandsize)
{ {
_heapchk();
M_Free (expand); M_Free (expand);
_heapchk();
I_Error ("Could not decompress cfile"); I_Error ("Could not decompress cfile");
} }
} }
@ -497,7 +500,18 @@ bool FCompressedMemFile::Reopen ()
m_Mode = EReading; m_Mode = EReading;
m_Buffer = m_ImplodedBuffer; m_Buffer = m_ImplodedBuffer;
m_SourceFromMem = true; m_SourceFromMem = true;
try
{
Explode (); 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; m_SourceFromMem = false;
return true; return true;
} }

View File

@ -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 () static void STACK_ARGS NewFailure ()
{ {
I_FatalError ("Failed to allocate memory from system heap"); I_FatalError ("Failed to allocate memory from system heap");
@ -323,7 +309,6 @@ int main (int argc, char **argv)
try try
{ {
Args = new DArgs(argc, argv); Args = new DArgs(argc, argv);
atterm(FinalGC);
/* /*
killough 1/98: killough 1/98:

View File

@ -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 // LayoutErrorPane
@ -828,7 +813,6 @@ void DoMain (HINSTANCE hInstance)
#endif #endif
Args = new DArgs(__argc, __argv); Args = new DArgs(__argc, __argv);
atterm(FinalGC);
// Under XP, get our session ID so we can know when the user changes/locks sessions. // 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 // Since we need to remain binary compatible with older versions of Windows, we