diff options
author | Eugene Sandulenko | 2017-01-05 08:28:32 +0100 |
---|---|---|
committer | GitHub | 2017-01-05 08:28:32 +0100 |
commit | 11812d9af9fa8ff6ca78496ea54fd5a16c822676 (patch) | |
tree | 8b368378fd3a5801f84f54c5d25c89c136b5f33b | |
parent | b7bf9e87725d8d26f686015e478e63ab0a55f77c (diff) | |
parent | b4514bfe92307249d5b52c3c37d5838ea2e3c4d5 (diff) | |
download | scummvm-rg350-11812d9af9fa8ff6ca78496ea54fd5a16c822676.tar.gz scummvm-rg350-11812d9af9fa8ff6ca78496ea54fd5a16c822676.tar.bz2 scummvm-rg350-11812d9af9fa8ff6ca78496ea54fd5a16c822676.zip |
Merge pull request #883 from bluegr/fullpipe_mem
FULLPIPE: Plug some memory leaks
-rw-r--r-- | engines/fullpipe/gameloader.cpp | 6 | ||||
-rw-r--r-- | engines/fullpipe/gameloader.h | 2 | ||||
-rw-r--r-- | engines/fullpipe/input.cpp | 3 | ||||
-rw-r--r-- | engines/fullpipe/messagehandlers.cpp | 2 | ||||
-rw-r--r-- | engines/fullpipe/messages.cpp | 11 | ||||
-rw-r--r-- | engines/fullpipe/messages.h | 4 | ||||
-rw-r--r-- | engines/fullpipe/scene.cpp | 2 | ||||
-rw-r--r-- | engines/fullpipe/sound.cpp | 4 | ||||
-rw-r--r-- | engines/fullpipe/sound.h | 1 | ||||
-rw-r--r-- | engines/fullpipe/stateloader.cpp | 9 |
10 files changed, 20 insertions, 24 deletions
diff --git a/engines/fullpipe/gameloader.cpp b/engines/fullpipe/gameloader.cpp index aebf73dbe4..efa5f8c2c7 100644 --- a/engines/fullpipe/gameloader.cpp +++ b/engines/fullpipe/gameloader.cpp @@ -55,7 +55,6 @@ GameLoader::GameLoader() { _inputController = new InputController(); _gameProject = 0; - _gameName = 0; addMessageHandlerByIndex(global_messageHandler2, 0, 0); insertMessageHandler(global_messageHandler3, 0, 128); @@ -78,7 +77,6 @@ GameLoader::GameLoader() { } GameLoader::~GameLoader() { - free(_gameName); delete _gameProject; delete _interactionController; delete _inputController; @@ -112,7 +110,7 @@ bool GameLoader::load(MfcArchive &file) { debugC(1, kDebugLoading, "GameLoader::load()"); _gameName = file.readPascalString(); - debugC(1, kDebugLoading, "_gameName: %s", _gameName); + debugC(1, kDebugLoading, "_gameName: %s", _gameName.c_str()); _gameProject = new GameProject(); @@ -125,7 +123,7 @@ bool GameLoader::load(MfcArchive &file) { } _gameName = file.readPascalString(); - debugC(1, kDebugLoading, "_gameName: %s", _gameName); + debugC(1, kDebugLoading, "_gameName: %s", _gameName.c_str()); _inventory.load(file); diff --git a/engines/fullpipe/gameloader.h b/engines/fullpipe/gameloader.h index a6c2416aae..6180ab0347 100644 --- a/engines/fullpipe/gameloader.h +++ b/engines/fullpipe/gameloader.h @@ -133,7 +133,7 @@ class GameLoader : public CObject { int16 _field_FA; PreloadItems _preloadItems; GameVar *_gameVar; - char *_gameName; + Common::String _gameName; ExCommand _exCommand; int _updateCounter; int _preloadSceneId; diff --git a/engines/fullpipe/input.cpp b/engines/fullpipe/input.cpp index 55735624c6..55bc21716e 100644 --- a/engines/fullpipe/input.cpp +++ b/engines/fullpipe/input.cpp @@ -56,6 +56,9 @@ InputController::~InputController() { removeMessageHandler(126, -1); g_fp->_inputController = 0; + + for (int i = 0; i < _cursorsArray.size(); i++) + delete _cursorsArray[i]; } void InputController::setInputDisabled(bool state) { diff --git a/engines/fullpipe/messagehandlers.cpp b/engines/fullpipe/messagehandlers.cpp index f53a705ea9..bd75e01232 100644 --- a/engines/fullpipe/messagehandlers.cpp +++ b/engines/fullpipe/messagehandlers.cpp @@ -519,7 +519,7 @@ int global_messageHandler3(ExCommand *cmd) { if (cmd->_objtype == kObjTypeObjstateCommand) { ObjstateCommand *c = (ObjstateCommand *)cmd; result = 1; - g_fp->setObjectState(c->_objCommandName, c->_value); + g_fp->setObjectState(c->_objCommandName.c_str(), c->_value); } return result; default: diff --git a/engines/fullpipe/messages.cpp b/engines/fullpipe/messages.cpp index a9fc5210a3..111c70ce05 100644 --- a/engines/fullpipe/messages.cpp +++ b/engines/fullpipe/messages.cpp @@ -232,20 +232,17 @@ Message::Message(int16 parentId, int messageKind, int x, int y, int a6, int a7, ObjstateCommand::ObjstateCommand() { _value = 0; - _objCommandName = 0; _objtype = kObjTypeObjstateCommand; } ObjstateCommand::ObjstateCommand(ObjstateCommand *src) : ExCommand(src) { _value = src->_value; - _objCommandName = (char *)calloc(strlen(src->_objCommandName) + 1, 1); _objtype = kObjTypeObjstateCommand; - strncpy(_objCommandName, src->_objCommandName, strlen(src->_objCommandName)); + _objCommandName = src->_objCommandName; } ObjstateCommand::~ObjstateCommand() { - free(_objCommandName); } bool ObjstateCommand::load(MfcArchive &file) { @@ -273,7 +270,6 @@ MessageQueue::MessageQueue() { _id = 0; _isFinished = 0; _flags = 0; - _queueName = 0; _counter = 0; _field_38 = 0; _flag1 = 0; @@ -286,7 +282,6 @@ MessageQueue::MessageQueue(int dataId) { _id = g_fp->_globalMessageQueueList->compact(); _isFinished = 0; _flags = 0; - _queueName = 0; _counter = 0; _field_38 = 0; _flag1 = 0; @@ -312,7 +307,7 @@ MessageQueue::MessageQueue(MessageQueue *src, int parId, int field_38) { _id = g_fp->_globalMessageQueueList->compact(); _dataId = src->_dataId; _flags = src->_flags; - _queueName = 0; + _queueName = ""; g_fp->_globalMessageQueueList->addMessageQueue(this); @@ -338,8 +333,6 @@ MessageQueue::~MessageQueue() { } finish(); - - free(_queueName); } bool MessageQueue::load(MfcArchive &file) { diff --git a/engines/fullpipe/messages.h b/engines/fullpipe/messages.h index b99b842bf9..0bdfb23835 100644 --- a/engines/fullpipe/messages.h +++ b/engines/fullpipe/messages.h @@ -94,7 +94,7 @@ class ExCommand2 : public ExCommand { class ObjstateCommand : public ExCommand { public: - char *_objCommandName; + Common::String _objCommandName; int _value; public: @@ -111,7 +111,7 @@ class MessageQueue : public CObject { public: int _id; int _flags; - char *_queueName; + Common::String _queueName; int16 _dataId; CObject *_field_14; int _counter; diff --git a/engines/fullpipe/scene.cpp b/engines/fullpipe/scene.cpp index efd07b9455..4e3678bfb4 100644 --- a/engines/fullpipe/scene.cpp +++ b/engines/fullpipe/scene.cpp @@ -401,7 +401,7 @@ MessageQueue *Scene::getMessageQueueById(int messageId) { MessageQueue *Scene::getMessageQueueByName(char *name) { for (uint i = 0; i < _messageQueueList.size(); i++) - if (!strcmp(_messageQueueList[i]->_queueName, name)) + if (!strcmp(_messageQueueList[i]->_queueName.c_str(), name)) return _messageQueueList[i]; return 0; diff --git a/engines/fullpipe/sound.cpp b/engines/fullpipe/sound.cpp index be539bc10e..1a88e47134 100644 --- a/engines/fullpipe/sound.cpp +++ b/engines/fullpipe/sound.cpp @@ -102,14 +102,12 @@ Sound::Sound() { _soundData = 0; _objectId = 0; memset(_directSoundBuffers, 0, sizeof(_directSoundBuffers)); - _description = 0; _volume = 100; _handle = new Audio::SoundHandle(); } Sound::~Sound() { freeSound(); - free(_description); delete _handle; } @@ -119,7 +117,7 @@ bool Sound::load(MfcArchive &file, NGIArchive *archive) { MemoryObject::load(file); _id = file.readUint32LE(); - _description = file.readPascalString(); + /*_description = */file.readPascalString(); assert(g_fp->_gameProjectVersion >= 6); diff --git a/engines/fullpipe/sound.h b/engines/fullpipe/sound.h index 4066c5e99e..bfc38829d6 100644 --- a/engines/fullpipe/sound.h +++ b/engines/fullpipe/sound.h @@ -31,7 +31,6 @@ namespace Fullpipe { class Sound : public MemoryObject { int _id; - char *_description; int _directSoundBuffer; int _directSoundBuffers[7]; byte *_soundData; diff --git a/engines/fullpipe/stateloader.cpp b/engines/fullpipe/stateloader.cpp index adc4fe3731..86865f928a 100644 --- a/engines/fullpipe/stateloader.cpp +++ b/engines/fullpipe/stateloader.cpp @@ -69,18 +69,21 @@ bool GameLoader::readSavegame(const char *fname) { byte *map = (byte *)malloc(800); saveFile->read(map, 800); - MfcArchive temp(new Common::MemoryReadStream(map, 800)); + Common::MemoryReadStream *tempStream = new Common::MemoryReadStream(map, 800); + MfcArchive temp(tempStream); if (_savegameCallback) _savegameCallback(&temp, false); + delete tempStream; delete saveFile; // Deobfuscate the data for (int i = 0; i < header.encSize; i++) data[i] -= i & 0x7f; - MfcArchive *archive = new MfcArchive(new Common::MemoryReadStream(data, header.encSize)); + Common::MemoryReadStream *archiveStream = new Common::MemoryReadStream(data, header.encSize); + MfcArchive *archive = new MfcArchive(archiveStream); GameVar *var = (GameVar *)archive->readClass(); @@ -91,6 +94,7 @@ bool GameLoader::readSavegame(const char *fname) { if (!v) { warning("No state to save"); + delete archiveStream; delete archive; return false; } @@ -121,6 +125,7 @@ bool GameLoader::readSavegame(const char *fname) { _sc2array[i]._isLoaded = 0; } + delete archiveStream; delete archive; getGameLoaderInventory()->rebuildItemRects(); |