From 070c0a9e3057eac42453b974ebb4031671b5619c Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 25 Jul 2013 21:42:30 -0500 Subject: [PATCH] Stop leaking function damage expressions. - Function damage expressions parsed from DECORATE are now stored in a single array and deleted at the end of FinishThingdef(). --- src/thingdef/thingdef.cpp | 8 +++++++- src/thingdef/thingdef.h | 1 + src/thingdef/thingdef_properties.cpp | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index 8a3589a99..36c09d716 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -66,6 +66,8 @@ #include "vmbuilder.h" #include "stats.h" +TDeletingArray ActorDamageFuncs; + // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- void InitThingdef(); void ParseDecorate (FScanner &sc); @@ -351,8 +353,8 @@ static void FinishThingdef() if (def->Damage != NULL) { + FxDamageValue *dmg = (FxDamageValue *)ActorDamageFuncs[(uintptr_t)def->Damage - 1]; VMScriptFunction *sfunc; - FxDamageValue *dmg = (FxDamageValue *)def->Damage; sfunc = dmg->GetFunction(); if (sfunc == NULL) { @@ -389,6 +391,9 @@ static void FinishThingdef() I_Error("%d errors during actor postprocessing", errorcount); } + ActorDamageFuncs.DeleteAndClear(); + StateTempCalls.DeleteAndClear(); + // Since these are defined in DECORATE now the table has to be initialized here. for(int i = 0; i < 31; i++) { @@ -415,6 +420,7 @@ void LoadActors () timer.Reset(); timer.Clock(); StateParams.Clear(); + ActorDamageFuncs.Clear(); GlobalSymbols.ReleaseSymbols(); FScriptPosition::ResetErrorCounter(); InitThingdef(); diff --git a/src/thingdef/thingdef.h b/src/thingdef/thingdef.h index 76479bc4d..b65bb4637 100644 --- a/src/thingdef/thingdef.h +++ b/src/thingdef/thingdef.h @@ -154,6 +154,7 @@ public: extern FStateExpressions StateParams; +extern TDeletingArray ActorDamageFuncs; //========================================================================== // diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index b1df39d90..12cb318b1 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -544,7 +544,14 @@ DEFINE_PROPERTY(damage, X, Actor) // Store this expression here for now. It will be converted to a function // later once all actors have been processed. - defaults->Damage = (VMFunction *)id; + if (id == NULL) + { + defaults->Damage = NULL; + } + else + { + defaults->Damage = (VMFunction *)(uintptr_t)(ActorDamageFuncs.Push(id) + 1); + } } //==========================================================================