- added explicit clearing of global VM stask

When exception is thrown from JITed code, VM stask isn't cleared during unwinding
It needs to be clear explicitly to avoid memory leaks and references to destructed objects on shutdown

https://forum.zdoom.org/viewtopic.php?t=66172
This commit is contained in:
alexey.lysiuk 2019-10-21 15:54:13 +03:00
parent ed337b3ecc
commit 994960627b
4 changed files with 12 additions and 0 deletions

View file

@ -984,6 +984,7 @@ void D_ErrorCleanup ()
} }
if (gamestate == GS_INTERMISSION) gamestate = GS_DEMOSCREEN; if (gamestate == GS_INTERMISSION) gamestate = GS_DEMOSCREEN;
insave = false; insave = false;
ClearGlobalVMStack();
} }
//========================================================================== //==========================================================================

View file

@ -250,6 +250,7 @@ void FThinkerCollection::DestroyAllThinkers()
GC::FullGC(); GC::FullGC();
if (error) if (error)
{ {
ClearGlobalVMStack();
I_Error("DestroyAllThinkers failed"); I_Error("DestroyAllThinkers failed");
} }
} }

View file

@ -110,6 +110,8 @@ public:
void ThrowAbortException(EVMAbortException reason, const char *moreinfo, ...); void ThrowAbortException(EVMAbortException reason, const char *moreinfo, ...);
void ThrowAbortException(VMScriptFunction *sfunc, VMOP *line, EVMAbortException reason, const char *moreinfo, ...); void ThrowAbortException(VMScriptFunction *sfunc, VMOP *line, EVMAbortException reason, const char *moreinfo, ...);
void ClearGlobalVMStack();
struct VMReturn struct VMReturn
{ {
void *Location; void *Location;

View file

@ -715,6 +715,14 @@ void ThrowVMException(VMException *x)
#endif #endif
void ClearGlobalVMStack()
{
while (GlobalVMStack.PopFrame() != nullptr)
{
}
}
ADD_STAT(VM) ADD_STAT(VM)
{ {
double added = 0; double added = 0;