From 14a6ff0810b926d79808b3ff72d8a6ff8ee781d5 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Tue, 14 Nov 2017 13:53:01 -0600 Subject: FULLPIPE: Fix memory leaks of MovTable and remove unnecessary extra class --- engines/fullpipe/fullpipe.cpp | 2 -- engines/fullpipe/fullpipe.h | 4 ++-- engines/fullpipe/gameloader.cpp | 2 +- engines/fullpipe/stateloader.cpp | 2 +- engines/fullpipe/statics.cpp | 17 +++++++---------- engines/fullpipe/statics.h | 9 +-------- 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/engines/fullpipe/fullpipe.cpp b/engines/fullpipe/fullpipe.cpp index 4e05f899c3..6f8e642cc6 100644 --- a/engines/fullpipe/fullpipe.cpp +++ b/engines/fullpipe/fullpipe.cpp @@ -137,7 +137,6 @@ FullpipeEngine::FullpipeEngine(OSystem *syst, const ADGameDescription *gameDesc) _loaderScene = nullptr; _scene2 = nullptr; _scene3 = nullptr; - _movTable = nullptr; _messageHandlers = nullptr; _updateScreenCallback = nullptr; @@ -452,7 +451,6 @@ void FullpipeEngine::updateEvents() { void FullpipeEngine::freeGameLoader() { setCursor(0); - delete _movTable; _floaters->stopAll(); _gameLoader.reset(); _currentScene = 0; diff --git a/engines/fullpipe/fullpipe.h b/engines/fullpipe/fullpipe.h index 9426c32573..e6a3fded1a 100644 --- a/engines/fullpipe/fullpipe.h +++ b/engines/fullpipe/fullpipe.h @@ -77,7 +77,6 @@ class GameObject; class GlobalMessageQueueList; struct MessageHandler; class MessageQueue; -struct MovTable; class AniHandler; class NGIArchive; class PictureObject; @@ -86,6 +85,7 @@ class Scene; class SoundList; class StaticANIObject; class Vars; +typedef Common::Array MovTable; typedef Common::Array Palette; int global_messageHandler1(ExCommand *cmd); @@ -217,7 +217,7 @@ public: Common::ScopedPtr _behaviorManager; - MovTable *_movTable; + Common::ScopedPtr _movTable; Common::ScopedPtr _floaters; Common::ScopedPtr _aniHandler; diff --git a/engines/fullpipe/gameloader.cpp b/engines/fullpipe/gameloader.cpp index 4ed1890de5..f2c078a7fa 100644 --- a/engines/fullpipe/gameloader.cpp +++ b/engines/fullpipe/gameloader.cpp @@ -253,7 +253,7 @@ bool GameLoader::gotoScene(int sceneId, int entranceId) { bool preloadCallback(PreloadItem &pre, int flag) { if (flag) { if (flag == 50) - g_fp->_aniMan->preloadMovements(g_fp->_movTable); + g_fp->_aniMan->preloadMovements(g_fp->_movTable.get()); StaticANIObject *pbar = g_fp->_loaderScene->getStaticANIObject1ById(ANI_PBAR, -1); diff --git a/engines/fullpipe/stateloader.cpp b/engines/fullpipe/stateloader.cpp index de10f2e34c..0ff8c60d42 100644 --- a/engines/fullpipe/stateloader.cpp +++ b/engines/fullpipe/stateloader.cpp @@ -310,7 +310,7 @@ bool FullpipeEngine::loadGam(const char *fname, int scene) { _aniMan = accessScene(SC_COMMON)->getAniMan(); _scene2 = 0; - _movTable = _aniMan->countMovements(); + _movTable.reset(_aniMan->countMovements()); _aniMan->setSpeed(1); diff --git a/engines/fullpipe/statics.cpp b/engines/fullpipe/statics.cpp index 223cc8c6d6..185a7e5797 100644 --- a/engines/fullpipe/statics.cpp +++ b/engines/fullpipe/statics.cpp @@ -668,22 +668,19 @@ MovTable *StaticANIObject::countMovements() { GameVar *preloadSubVar = g_fp->getGameLoaderGameVar()->getSubVarByName(getName())->getSubVarByName("PRELOAD"); if (!preloadSubVar || preloadSubVar->getSubVarsCount() == 0) - return 0; + return nullptr; MovTable *movTable = new MovTable; - - movTable->count = _movements.size(); - movTable->movs = (int16 *)calloc(_movements.size(), sizeof(int16)); - + movTable->reserve(_movements.size()); for (uint i = 0; i < _movements.size(); i++) { - movTable->movs[i] = 2; - + int16 value = 2; for (GameVar *sub = preloadSubVar->_subVars; sub; sub = sub->_nextVarObj) { if (scumm_stricmp(_movements[i]->getName().c_str(), sub->_varName.c_str()) == 0) { - movTable->movs[i] = 1; + value = 1; break; } } + movTable->push_back(value); } return movTable; @@ -728,9 +725,9 @@ void StaticANIObject::preloadMovements(MovTable *mt) { for (uint i = 0; i < _movements.size(); i++) { Movement *mov = _movements[i]; - if (mt->movs[i] == 1) + if ((*mt)[i] == 1) mov->loadPixelData(); - else if (mt->movs[i] == 2) + else if ((*mt)[i] == 2) mov->freePixelData(); } } diff --git a/engines/fullpipe/statics.h b/engines/fullpipe/statics.h index 46b4a4bf9c..462a76c619 100644 --- a/engines/fullpipe/statics.h +++ b/engines/fullpipe/statics.h @@ -244,6 +244,7 @@ public: void draw(); void draw2(); + /** ownership of returned object is transferred to caller */ MovTable *countMovements(); Common::Point *calcStepLen(Common::Point *p); void setSpeed(int speed); @@ -259,14 +260,6 @@ public: bool isPixelHitAtPos(int x, int y); }; -struct MovTable { - int count; - int16 *movs; - - MovTable() { count = 0; movs = 0; } - ~MovTable() { free(movs); } -}; - } // End of namespace Fullpipe #endif /* FULLPIPE_STATICS_H */ -- cgit v1.2.3