From ec999f1cb74dff8c42c69898bb6cbc3823b169dd Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 9 Apr 2015 13:44:39 +0300 Subject: MADS: Plug some memory leaks Surfaces should be freed (to free their inner allocated surface buffers) before being deleted --- engines/mads/game.cpp | 1 + engines/mads/nebular/dialogs_nebular.cpp | 4 +++- engines/mads/scene_data.cpp | 2 ++ engines/mads/sprites.cpp | 4 +++- engines/mads/user_interface.cpp | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 72d7988c05..3d1c194612 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -100,6 +100,7 @@ Game::~Game() { } delete _saveFile; + _surface->free(); delete _surface; delete _sectionHandler; } diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp index 10715797ed..5b9942db07 100644 --- a/engines/mads/nebular/dialogs_nebular.cpp +++ b/engines/mads/nebular/dialogs_nebular.cpp @@ -430,7 +430,7 @@ void CopyProtectionDialog::show() { draw(); Common::KeyState curKey; - Common::Rect inputArea(110, 165, 210, 175); + const Common::Rect inputArea(110, 165, 210, 175); MSurface *origInput = new MSurface(inputArea.width(), inputArea.height()); _vm->_screen.frameRect(inputArea, TEXTDIALOG_BLACK); _vm->_screen.copyTo(origInput, inputArea, Common::Point(0, 0)); @@ -471,6 +471,7 @@ void CopyProtectionDialog::show() { _vm->_screen.updateScreen(); } + origInput->free(); delete origInput; } @@ -592,6 +593,7 @@ void PictureDialog::save() { void PictureDialog::restore() { if (_savedSurface) { _savedSurface->copyTo(&_vm->_screen); + _savedSurface->free(); delete _savedSurface; _savedSurface = nullptr; diff --git a/engines/mads/scene_data.cpp b/engines/mads/scene_data.cpp index d0e96be1d7..e594406447 100644 --- a/engines/mads/scene_data.cpp +++ b/engines/mads/scene_data.cpp @@ -451,6 +451,8 @@ void SceneInfo::loadMadsV2Background(int sceneId, const Common::String &resName, fab.decompress(compressedTileData, compressedTileDataSize, (byte*)newTile->getPixels(), tileWidth * tileHeight); tileSet.push_back(TileSetList::value_type(newTile)); + newTile->free(); + delete newTile; delete[] compressedTileData; } diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index bc36b5575a..f15d6456d3 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -347,8 +347,10 @@ void SpriteSlots::drawSprites(MSurface *s) { spr->copyTo(s, Common::Point(xp, yp), sprite->getTransparencyIndex()); // Free sprite if it was a flipped one - if (flipped) + if (flipped) { + spr->free(); delete spr; + } } } } diff --git a/engines/mads/user_interface.cpp b/engines/mads/user_interface.cpp index 93a555d9c7..1e5a1d80d2 100644 --- a/engines/mads/user_interface.cpp +++ b/engines/mads/user_interface.cpp @@ -164,6 +164,7 @@ void UISlots::draw(bool updateFlag, bool delFlag) { MSurface *spr = sprite->flipHorizontal(); userInterface.mergeFrom(spr, spr->getBounds(), slot._position, sprite->getTransparencyIndex()); + spr->free(); delete spr; } else { userInterface.mergeFrom(sprite, sprite->getBounds(), slot._position, -- cgit v1.2.3