diff options
author | Colin Snover | 2017-11-16 23:47:57 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2017-11-18 22:35:12 +0100 |
commit | c9327f29859dcbbeca99a116d9ce2aebf366ced1 (patch) | |
tree | 823c5400e292ba1f4b72b73a7426245495d9f84a /engines | |
parent | 7323bef77bd6acf180a6316950c06723075e8299 (diff) | |
download | scummvm-rg350-c9327f29859dcbbeca99a116d9ce2aebf366ced1.tar.gz scummvm-rg350-c9327f29859dcbbeca99a116d9ce2aebf366ced1.tar.bz2 scummvm-rg350-c9327f29859dcbbeca99a116d9ce2aebf366ced1.zip |
FULLPIPE: Fix memory leaks of PreloadItems
Diffstat (limited to 'engines')
-rw-r--r-- | engines/fullpipe/gameloader.cpp | 31 | ||||
-rw-r--r-- | engines/fullpipe/gameloader.h | 4 | ||||
-rw-r--r-- | engines/fullpipe/lift.cpp | 6 | ||||
-rw-r--r-- | engines/fullpipe/modal.cpp | 24 |
4 files changed, 32 insertions, 33 deletions
diff --git a/engines/fullpipe/gameloader.cpp b/engines/fullpipe/gameloader.cpp index 58d3a4cade..e6f5b0858d 100644 --- a/engines/fullpipe/gameloader.cpp +++ b/engines/fullpipe/gameloader.cpp @@ -347,8 +347,8 @@ bool preloadCallback(PreloadItem &pre, int flag) { return true; } -void GameLoader::addPreloadItem(PreloadItem *item) { - _preloadItems.push_back(new PreloadItem(*item)); +void GameLoader::addPreloadItem(const PreloadItem &item) { + _preloadItems.push_back(item); } bool GameLoader::preloadScene(int sceneId, int entranceId) { @@ -363,7 +363,7 @@ bool GameLoader::preloadScene(int sceneId, int entranceId) { int idx = -1; for (uint i = 0; i < _preloadItems.size(); i++) - if (_preloadItems[i]->preloadId1 == sceneId && _preloadItems[i]->preloadId2 == entranceId) { + if (_preloadItems[i].preloadId1 == sceneId && _preloadItems[i].preloadId2 == entranceId) { idx = i; break; } @@ -375,7 +375,7 @@ bool GameLoader::preloadScene(int sceneId, int entranceId) { } if (_preloadCallback) { - if (!_preloadCallback(*_preloadItems[idx], 0)) + if (!_preloadCallback(_preloadItems[idx], 0)) return false; } @@ -387,19 +387,19 @@ bool GameLoader::preloadScene(int sceneId, int entranceId) { unloadScene(sceneId); if (_preloadCallback) - _preloadCallback(*_preloadItems[idx], 50); + _preloadCallback(_preloadItems[idx], 50); - loadScene(_preloadItems[idx]->sceneId); + loadScene(_preloadItems[idx].sceneId); - ExCommand *ex = new ExCommand(_preloadItems[idx]->sceneId, 17, 62, 0, 0, 0, 1, 0, 0, 0); + ExCommand *ex = new ExCommand(_preloadItems[idx].sceneId, 17, 62, 0, 0, 0, 1, 0, 0, 0); ex->_excFlags = 2; - ex->_param = _preloadItems[idx]->param; + ex->_param = _preloadItems[idx].param; _preloadSceneId = 0; _preloadEntranceId = 0; if (_preloadCallback) - _preloadCallback(*_preloadItems[idx], 100); + _preloadCallback(_preloadItems[idx], 100); ex->postMessage(); @@ -633,14 +633,13 @@ bool PreloadItems::load(MfcArchive &file) { clear(); + resize(count); for (int i = 0; i < count; i++) { - PreloadItem *t = new PreloadItem(); - t->preloadId1 = file.readUint32LE(); - t->preloadId2 = file.readUint32LE(); - t->sceneId = file.readUint32LE(); - t->param = file.readSint32LE(); - - push_back(t); + PreloadItem &t = (*this)[i]; + t.preloadId1 = file.readUint32LE(); + t.preloadId2 = file.readUint32LE(); + t.sceneId = file.readUint32LE(); + t.param = file.readSint32LE(); } return true; diff --git a/engines/fullpipe/gameloader.h b/engines/fullpipe/gameloader.h index 1279dd8810..f76a96f494 100644 --- a/engines/fullpipe/gameloader.h +++ b/engines/fullpipe/gameloader.h @@ -71,7 +71,7 @@ struct PreloadItem { bool preloadCallback(PreloadItem &pre, int flag); -class PreloadItems : public Common::Array<PreloadItem *>, public CObject { +class PreloadItems : public Common::Array<PreloadItem>, public CObject { public: virtual bool load(MfcArchive &file); }; @@ -105,7 +105,7 @@ class GameLoader : public CObject { bool preloadScene(int sceneId, int entranceId); bool unloadScene(int sceneId); - void addPreloadItem(PreloadItem *item); + void addPreloadItem(const PreloadItem &item); void updateSystems(int counterdiff); diff --git a/engines/fullpipe/lift.cpp b/engines/fullpipe/lift.cpp index 1bbe5a726b..feee335555 100644 --- a/engines/fullpipe/lift.cpp +++ b/engines/fullpipe/lift.cpp @@ -403,12 +403,12 @@ void FullpipeEngine::lift_goAnimation() { int numItems = _gameLoader->_preloadItems.size(); for (int i = 0; i < numItems; i++) { - PreloadItem *pre = _gameLoader->_preloadItems[i]; + PreloadItem &pre = _gameLoader->_preloadItems[i]; - if (pre->preloadId2 == buttonId && pre->preloadId1 == _currentScene->_sceneId) { + if (pre.preloadId2 == buttonId && pre.preloadId1 == _currentScene->_sceneId) { MessageQueue *mq = new MessageQueue(_globalMessageQueueList->compact()); - ExCommand *ex = new ExCommand(ANI_MAN, 1, (pre->param != LiftDown ? MV_MAN_LIFTDOWN : MV_MAN_LIFTUP), 0, 0, 0, 1, 0, 0, 0); + ExCommand *ex = new ExCommand(ANI_MAN, 1, (pre.param != LiftDown ? MV_MAN_LIFTDOWN : MV_MAN_LIFTUP), 0, 0, 0, 1, 0, 0, 0); ex->_param = -1; ex->_field_24 = 1; diff --git a/engines/fullpipe/modal.cpp b/engines/fullpipe/modal.cpp index 0f9877a0af..a513cd405c 100644 --- a/engines/fullpipe/modal.cpp +++ b/engines/fullpipe/modal.cpp @@ -570,10 +570,10 @@ bool ModalMap::init2(int counterdiff) { int ModalMap::findMapSceneId(int picId) { for (uint i = 0; i < g_fp->_gameLoader->_preloadItems.size(); i++) { - PreloadItem *pitem = g_fp->_gameLoader->_preloadItems[i]; + PreloadItem &pitem = g_fp->_gameLoader->_preloadItems[i]; - if (pitem->preloadId1 == SC_MAP && pitem->preloadId2 == picId) { - return pitem->sceneId; + if (pitem.preloadId1 == SC_MAP && pitem.preloadId2 == picId) { + return pitem.sceneId; } } @@ -705,11 +705,11 @@ void ModalMap::clickButton(PictureObject *pic) { return; } - PreloadItem *pitem = 0; + PreloadItem *pitem = nullptr; for (uint i = 0; i < g_fp->_gameLoader->_preloadItems.size(); i++) - if (g_fp->_gameLoader->_preloadItems[i]->preloadId2 == SC_MAP) { - pitem = g_fp->_gameLoader->_preloadItems[i]; + if (g_fp->_gameLoader->_preloadItems[i].preloadId2 == SC_MAP) { + pitem = &g_fp->_gameLoader->_preloadItems[i]; break; } @@ -717,16 +717,16 @@ void ModalMap::clickButton(PictureObject *pic) { PreloadItem preload; preload.preloadId2 = SC_MAP; - g_fp->_gameLoader->addPreloadItem(&preload); - pitem = g_fp->_gameLoader->_preloadItems[g_fp->_gameLoader->_preloadItems.size() - 1]; + g_fp->_gameLoader->addPreloadItem(preload); + pitem = &g_fp->_gameLoader->_preloadItems[g_fp->_gameLoader->_preloadItems.size() - 1]; } - PreloadItem *pitem2 = 0; + PreloadItem *pitem2 = nullptr; for (uint i = 0; i < g_fp->_gameLoader->_preloadItems.size(); i++) - if (g_fp->_gameLoader->_preloadItems[i]->preloadId1 == SC_MAP && - g_fp->_gameLoader->_preloadItems[i]->preloadId2 == pic->_id) { - pitem2 = g_fp->_gameLoader->_preloadItems[i]; + if (g_fp->_gameLoader->_preloadItems[i].preloadId1 == SC_MAP && + g_fp->_gameLoader->_preloadItems[i].preloadId2 == pic->_id) { + pitem2 = &g_fp->_gameLoader->_preloadItems[i]; break; } |