diff options
author | Paul Gilbert | 2016-05-19 08:04:56 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-15 19:13:17 -0400 |
commit | 6fa65bbf0a1a57e47f36a3dd9e1c7a90af2888f6 (patch) | |
tree | f2b4b8a76a49996e1091864bd393021d98de04a5 /engines/titanic | |
parent | fc05032feded6af51ac1c0b05488e4eea2c6e891 (diff) | |
download | scummvm-rg350-6fa65bbf0a1a57e47f36a3dd9e1c7a90af2888f6.tar.gz scummvm-rg350-6fa65bbf0a1a57e47f36a3dd9e1c7a90af2888f6.tar.bz2 scummvm-rg350-6fa65bbf0a1a57e47f36a3dd9e1c7a90af2888f6.zip |
TITANIC: Add proper destruction of node chains
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/true_talk/tt_script_base.cpp | 11 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_script_base.h | 4 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_sentence.cpp | 21 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_sentence.h | 8 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_word.cpp | 7 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_word.h | 1 |
6 files changed, 47 insertions, 5 deletions
diff --git a/engines/titanic/true_talk/tt_script_base.cpp b/engines/titanic/true_talk/tt_script_base.cpp index 16783dec0f..a8e0940471 100644 --- a/engines/titanic/true_talk/tt_script_base.cpp +++ b/engines/titanic/true_talk/tt_script_base.cpp @@ -28,7 +28,7 @@ namespace Titanic { TTscriptBase::TTscriptBase(int v1, const char *charClass, int v2, const char *charName, int v3, int v4, int v5, int v6, int v7) : _charName(charName), _charClass(charClass), - _field4(0), _field8(0), _hist(nullptr), + _nodesP(nullptr), _field8(0), _hist(nullptr), _field20(0), _field24(0), _field28(0), _field2C(0), _field30(0), _field34(0), _field38(0), _field3C(0), _field40(0), _field44(0), _field48(0), _status(0) { @@ -50,6 +50,13 @@ TTscriptBase::TTscriptBase(int v1, const char *charClass, int v2, reset(); } +TTscriptBase::~TTscriptBase() { + if (_nodesP) { + _nodesP->deleteSiblings(); + delete _nodesP; + } +} + bool TTscriptBase::areNamesValid() { bool result = !_charName.isValid() && !_charClass.isValid(); _status = result ? 0 : 11; @@ -57,7 +64,7 @@ bool TTscriptBase::areNamesValid() { } void TTscriptBase::reset() { - _field4 = 0; + _nodesP = nullptr; _field8 = 4; _hist = nullptr; _field20 = 0; diff --git a/engines/titanic/true_talk/tt_script_base.h b/engines/titanic/true_talk/tt_script_base.h index 9bcb33467d..ce83cd13c4 100644 --- a/engines/titanic/true_talk/tt_script_base.h +++ b/engines/titanic/true_talk/tt_script_base.h @@ -25,6 +25,7 @@ #include "titanic/true_talk/tt_string.h" #include "titanic/true_talk/tt_hist.h" +#include "titanic/true_talk/tt_node.h" namespace Titanic { @@ -38,7 +39,7 @@ class TTscriptBase { private: void reset(); protected: - int _field4; + TTnode *_nodesP; int _field8; TThist *_hist; TTstring _charName, _charClass; @@ -57,6 +58,7 @@ protected: public: TTscriptBase(int v1, const char *charClass, int v2, const char *charName, int v3, int v4, int v5, int v6, int v7); + virtual ~TTscriptBase(); bool areNamesValid(); diff --git a/engines/titanic/true_talk/tt_sentence.cpp b/engines/titanic/true_talk/tt_sentence.cpp index f7779eb8bb..2654a55d67 100644 --- a/engines/titanic/true_talk/tt_sentence.cpp +++ b/engines/titanic/true_talk/tt_sentence.cpp @@ -27,7 +27,17 @@ namespace Titanic { TTsentenceSubBase::TTsentenceSubBase() : _field0(0), _field4(0), _field8(0), _fieldC(0), _field10(0), _field14(0), _field18(0), _field1C(0), - _field20(0), _field24(0) { + _nextP(nullptr), _field24(0) { +} + +void TTsentenceSubBase::deleteSiblings() { + // Iterate through the linked chain of nodes, deleting each in turn + for (TTsentenceSubBase *curP = _nextP, *nextP = nullptr; nextP; curP = nextP) { + nextP = curP->_nextP; + delete curP; + } + + _nextP = nullptr; } /*------------------------------------------------------------------------*/ @@ -45,6 +55,15 @@ TTsentence::TTsentence(const TTsentence *src) : _initialLine(src->_initialLine), copyFrom(*src); } +TTsentence::~TTsentence() { + _sub.deleteSiblings(); + + if (_nodesP) { + _nodesP->deleteSiblings(); + delete _nodesP; + } +} + void TTsentence::copyFrom(const TTsentence &src) { if (!src.getStatus()) _status = SS_5; diff --git a/engines/titanic/true_talk/tt_sentence.h b/engines/titanic/true_talk/tt_sentence.h index 9f6d18ee06..042e0558ac 100644 --- a/engines/titanic/true_talk/tt_sentence.h +++ b/engines/titanic/true_talk/tt_sentence.h @@ -42,10 +42,15 @@ public: int _field14; int _field18; int _field1C; - int _field20; + TTsentenceSubBase *_nextP; int _field24; public: TTsentenceSubBase(); + + /** + * Delete any sibling chain attached to this node + */ + void deleteSiblings(); }; class TTsentenceSub : public TTsentenceSubBase { @@ -78,6 +83,7 @@ public: TTsentence(int inputCtr, const TTstring &line, CScriptHandler *owner, TTroomScript *roomScript, TTnpcScript *npcScript); TTsentence(const TTsentence *src); + ~TTsentence(); void set34(int v) { _field34 = v; } void set38(int v) { _field38 = v; } diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp index bc029d001a..a4147a8662 100644 --- a/engines/titanic/true_talk/tt_word.cpp +++ b/engines/titanic/true_talk/tt_word.cpp @@ -68,6 +68,13 @@ TTword::TTword(TTword *src) { _field28 = src->_field28; } +TTword::~TTword() { + if (_synP) { + _synP->deleteSiblings(); + delete _synP; + } +} + void TTword::deleteSiblings() { while (_nextP) { TTword *next = _nextP; diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h index 7f0f916677..ed32b35814 100644 --- a/engines/titanic/true_talk/tt_word.h +++ b/engines/titanic/true_talk/tt_word.h @@ -52,6 +52,7 @@ public: public: TTword(TTstring &str, int mode, int val2); TTword(TTword *src); + ~TTword(); /** * Delete any following words chained to the word |