diff options
author | Borja Lorente | 2016-08-13 16:57:42 +0200 |
---|---|---|
committer | Borja Lorente | 2016-08-19 16:29:17 +0200 |
commit | 44a6f8a1dbdfa271aaa9ccf4b1ecc48e275ca11a (patch) | |
tree | a71afc88f925667dcd30c75395783abb67d1a5a2 | |
parent | 479f01b5a708ed1e3294ef1d553d37d270cb97c4 (diff) | |
download | scummvm-rg350-44a6f8a1dbdfa271aaa9ccf4b1ecc48e275ca11a.tar.gz scummvm-rg350-44a6f8a1dbdfa271aaa9ccf4b1ecc48e275ca11a.tar.bz2 scummvm-rg350-44a6f8a1dbdfa271aaa9ccf4b1ecc48e275ca11a.zip |
MACVENTURE: Fix minor memory leaks
-rw-r--r-- | engines/macventure/container.h | 13 | ||||
-rw-r--r-- | engines/macventure/gui.cpp | 11 | ||||
-rw-r--r-- | engines/macventure/image.cpp | 9 | ||||
-rw-r--r-- | engines/macventure/macventure.cpp | 22 | ||||
-rw-r--r-- | engines/macventure/script.cpp | 1 | ||||
-rw-r--r-- | engines/macventure/stringtable.h | 1 | ||||
-rw-r--r-- | engines/macventure/text.cpp | 3 | ||||
-rw-r--r-- | engines/macventure/world.cpp | 7 |
8 files changed, 57 insertions, 10 deletions
diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 013a11dafc..1abab1c6d0 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -52,6 +52,12 @@ public: _header = _res->readUint32BE(); _simplified = false; + for (uint i = 0; i < 16; ++i) + _huff.push_back(0); + + for (uint i = 0; i < 16; ++i) + _lens.push_back(0); + if (!(_header & 0x80000000)) { // Is simplified container _simplified = true; @@ -97,7 +103,8 @@ public: for (uint j = 0; j < 64; ++j) { uint32 length = 0; - uint32 mask = _res->readUint32BE(); + uint32 mask = 0; + mask = _res->readUint32BE(); mask >>= (16 - bits); mask &= 0xFFFF; debugC(11, kMVDebugContainer, "Load mask of object &%d:%d is %x", i, j, mask); @@ -202,8 +209,8 @@ protected: ContainerHeader _header; - uint16 _huff[15]; // huffman masks - uint8 _lens[16]; // huffman lengths + Common::Array<uint16> _huff; // huffman masks + Common::Array<uint8> _lens; // huffman lengths Common::Array<ItemGroup> _groups; Common::String _filename; diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 85f1cdbea7..f8f9497b8b 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -138,6 +138,9 @@ Gui::~Gui() { delete _dialog; clearAssets(); + + if (_graphics) + delete _graphics; } void Gui::initGUI() { @@ -421,6 +424,7 @@ bool Gui::loadMenus() { } i++; + delete res; } return true; @@ -463,12 +467,15 @@ bool Gui::loadWindows() { res->read(newTitle, data.titleLength); newTitle[data.titleLength] = '\0'; data.title = Common::String(newTitle); + delete[] newTitle; } data.scrollPos = Common::Point(0, 0); debugC(4, kMVDebugGUI, "Window loaded: %s", data.title.c_str()); _windowData->push_back(data); + + delete res; } return true; @@ -518,7 +525,9 @@ bool Gui::loadControls() { } - i++; + _controlData->push_back(CommandButton(data, this)); + + delete res; } return true; diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index a89eae94be..604d9dbfc6 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -98,9 +98,12 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array<byte> &data, uint &bitHeight return; } if (size == 2) { - realID = _container->getItem(id)->readUint16BE(); + Common::SeekableReadStream *newItemStream = _container->getItem(id); + realID = newItemStream->readUint16BE(); + delete newItemStream; } - Common::BitStream32BEMSB stream(_container->getItem(realID), true); + Common::SeekableReadStream *baseStream = _container->getItem(realID); + Common::BitStream32BEMSB stream(baseStream); uint8 mode = stream.getBits(3); int w, h; @@ -133,6 +136,8 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array<byte> &data, uint &bitHeight decodePPIC3(stream, data, bitHeight, bitWidth, rowBytes); break; } + + delete baseStream; } void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array<byte> &data, uint bitHeight, uint bitWidth, uint rowBytes) { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 21fb709994..81bb267dfa 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -55,7 +55,9 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD initDebugChannels(); _debugger = NULL; + _resourceManager = NULL; _gui = NULL; + _world = NULL; _scriptEngine = NULL; _filenames = NULL; @@ -82,9 +84,15 @@ MacVentureEngine::~MacVentureEngine() { if (_debugger) delete _debugger; + if (_resourceManager) + delete _resourceManager; + if (_gui) delete _gui; + if (_world) + delete _world; + if (_scriptEngine) delete _scriptEngine; @@ -471,6 +479,10 @@ Common::String MacVentureEngine::getStartGameFileName() { Common::String result = Common::String(fileName, length); // HACK, see definition of toASCII toASCII(result); + + delete[] fileName; + delete res; + return result; } @@ -1065,11 +1077,11 @@ ControlAction MacVentureEngine::getSelectedControl() { bool MacVentureEngine::loadGlobalSettings() { Common::MacResIDArray resArray; - Common::SeekableReadStream *res; if ((resArray = _resourceManager->getResIDArray(MKTAG('G', 'N', 'R', 'L'))).size() == 0) return false; + Common::SeekableReadStream *res; res = _resourceManager->getResource(MKTAG('G', 'N', 'R', 'L'), kGlobalSettingsID); if (res) { _globalSettings.numObjects = res->readUint16BE(); @@ -1103,9 +1115,9 @@ bool MacVentureEngine::loadGlobalSettings() { _globalSettings.commands = new uint8[_globalSettings.numCommands]; res->read(_globalSettings.commands, _globalSettings.numCommands); + delete res; return true; } - return false; } @@ -1136,6 +1148,12 @@ bool MacVentureEngine::loadTextHuffman() { _textHuffman = new HuffmanLists(numEntries, lengths, masks, values); debugC(4, kMVDebugMain, "Text is huffman-encoded"); + + + delete res; + delete masks; + delete lengths; + delete values; return true; } return false; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index a051ca8f75..5aa8e3cc19 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1208,6 +1208,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } + delete res; debugC(2, kMVDebugScript, "SCRIPT: Load %d instructions for script %d", amount, _id); } diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index f05b793ced..0a5419e235 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -90,6 +90,7 @@ private: delete[] str; } + delete res; return true; } diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 74b5685e7f..d15401ac3a 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -117,7 +117,7 @@ void TextAsset::decodeOld() { void TextAsset::decodeHuffman() { _decoded = Common::String(""); Common::SeekableReadStream *res = _container->getItem(_id); - Common::BitStream8MSB stream(res); + Common::BitStream8MSB stream(res, true); uint16 strLen = 0; if (stream.getBit()) { strLen = stream.getBits(15); @@ -174,6 +174,7 @@ void TextAsset::decodeHuffman() { } } _decoded += '\0'; + delete res; debugC(4, kMVDebugText, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); } Common::String TextAsset::getNoun(ObjID subval) { diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 82a8952f02..708ccfec33 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -9,6 +9,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _resourceManager = resMan; _engine = engine; _saveGame = NULL; + _gameText = NULL; startNewGame(); @@ -26,6 +27,9 @@ World::~World() { if (_objectConstants) delete _objectConstants; + + if (_gameText) + delete _gameText; } void World::startNewGame() { @@ -45,7 +49,7 @@ void World::startNewGame() { _saveGame = new SaveGame(_engine, saveGameRes); calculateObjectRelations(); - + delete saveGameRes; saveGameFile.close(); } @@ -70,6 +74,7 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { if (res & 0x8000) res = -((res ^ 0xffff) + 1); debugC(5, kMVDebugMain, "Attribute %x from object %x is %x", attrID, objID, res); + delete objStream; return res; } |