diff options
author | Paul Gilbert | 2016-11-05 21:44:51 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-11-05 21:44:51 -0400 |
commit | 0f17c9de479e8607707e6ab2a184d0e141f39904 (patch) | |
tree | fb6da7723de0868a1f7002e7b1ce78c15d4a46d1 /engines/titanic/core | |
parent | 6f614c350e465b1af1eed2096dbb557716db8ce5 (diff) | |
download | scummvm-rg350-0f17c9de479e8607707e6ab2a184d0e141f39904.tar.gz scummvm-rg350-0f17c9de479e8607707e6ab2a184d0e141f39904.tar.bz2 scummvm-rg350-0f17c9de479e8607707e6ab2a184d0e141f39904.zip |
TITANIC: Free allocated class type definitions on exit
Diffstat (limited to 'engines/titanic/core')
-rw-r--r-- | engines/titanic/core/saveable_object.cpp | 18 | ||||
-rw-r--r-- | engines/titanic/core/saveable_object.h | 8 |
2 files changed, 18 insertions, 8 deletions
diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index c4fdb494a1..b0009c3bc1 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -421,14 +421,15 @@ CSaveableObject *ClassDef::create() { /*------------------------------------------------------------------------*/ -Common::HashMap<Common::String, CSaveableObject::CreateFunction> * - CSaveableObject::_classList = nullptr; -Common::List<ClassDef *> *CSaveableObject::_classDefs; +CSaveableObject::ClassListMap *CSaveableObject::_classList = nullptr; +CSaveableObject::ClassDefList *CSaveableObject::_classDefs; +CSaveableObject::VoidArray *CSaveableObject::_typesToFree; #define DEFFN(T) CSaveableObject *Function##T() { return new T(); } \ ClassDef *T::_type #define ADDFN(CHILD, PARENT) \ CHILD::_type = new TypeTemplate<CHILD>(#CHILD, PARENT::_type); \ + _typesToFree->push_back(CHILD::_type); \ (*_classList)[#CHILD] = Function##CHILD DEFFN(CArm); @@ -1020,8 +1021,9 @@ DEFFN(CStarControl); DEFFN(CTimeEventInfo); void CSaveableObject::initClassList() { - _classDefs = new Common::List<ClassDef *>(); - _classList = new Common::HashMap<Common::String, CreateFunction>(); + _classDefs = new ClassDefList(); + _classList = new ClassListMap(); + _typesToFree = new VoidArray(); ADDFN(CArm, CCarry); ADDFN(CAuditoryCentre, CBrain); ADDFN(CBowlEar, CEar); @@ -1617,12 +1619,16 @@ void CSaveableObject::initClassList() { } void CSaveableObject::freeClassList() { - Common::List<ClassDef *>::iterator i; + ClassDefList::iterator i; for (i = _classDefs->begin(); i != _classDefs->end(); ++i) delete *i; + for (uint idx = 0; idx < _typesToFree->size(); ++idx) + delete (*_typesToFree)[idx]; + delete _classDefs; delete _classList; + delete _typesToFree; } CSaveableObject *CSaveableObject::createInstance(const Common::String &name) { diff --git a/engines/titanic/core/saveable_object.h b/engines/titanic/core/saveable_object.h index 4c7c1a7737..0591f0930c 100644 --- a/engines/titanic/core/saveable_object.h +++ b/engines/titanic/core/saveable_object.h @@ -59,8 +59,12 @@ public: class CSaveableObject { typedef CSaveableObject *(*CreateFunction)(); private: - static Common::List<ClassDef *> *_classDefs; - static Common::HashMap<Common::String, CreateFunction> *_classList; + typedef Common::List<ClassDef *> ClassDefList; + typedef Common::HashMap<Common::String, CreateFunction> ClassListMap; + typedef Common::Array<void *> VoidArray; + static ClassDefList *_classDefs; + static ClassListMap *_classList; + static VoidArray *_typesToFree; public: /** * Sets up the list of saveable object classes |