From c1046889411d4f38babd21b1b38c0cbd457caf10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Johan=20Tr=C3=B8an=20S=C3=B8ma=CC=8Aen?= Date: Thu, 14 Jun 2012 00:56:24 +0200 Subject: [PATCH] WINTERMUTE: Fix quite a lot of memory leaks. --- engines/wintermute/Base/BFontTT.cpp | 6 +++++- engines/wintermute/Base/BImage.cpp | 15 +++++++-------- engines/wintermute/Base/BSurfaceSDL.cpp | 6 +++++- engines/wintermute/video/VidTheoraPlayer.cpp | 8 ++++++++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/engines/wintermute/Base/BFontTT.cpp b/engines/wintermute/Base/BFontTT.cpp index 449767e3598..c2991f12774 100644 --- a/engines/wintermute/Base/BFontTT.cpp +++ b/engines/wintermute/Base/BFontTT.cpp @@ -278,8 +278,12 @@ CBSurface *CBFontTT::RenderTextToTexture(const WideString &text, int width, TTex } CBSurfaceSDL *retSurface = new CBSurfaceSDL(Game); - retSurface->putSurface(*surface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8 ,0)), true); + Graphics::Surface *convertedSurface = surface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8 ,0)); + retSurface->putSurface(*convertedSurface, true); + convertedSurface->free(); + surface->free(); delete surface; + delete convertedSurface; return retSurface; #if 0 //TODO int textHeight = lines.size() * (_maxCharHeight + _ascender); diff --git a/engines/wintermute/Base/BImage.cpp b/engines/wintermute/Base/BImage.cpp index bacfd9ece55..69859b4c050 100644 --- a/engines/wintermute/Base/BImage.cpp +++ b/engines/wintermute/Base/BImage.cpp @@ -67,16 +67,15 @@ CBImage::~CBImage() { HRESULT CBImage::loadFile(const Common::String &filename) { _filename = filename; - Graphics::ImageDecoder *imgDecoder; if (filename.hasSuffix(".png")) { - imgDecoder = new Graphics::PNGDecoder(); + _decoder = new Graphics::PNGDecoder(); } else if (filename.hasSuffix(".bmp")) { - imgDecoder = new Graphics::BitmapDecoder(); + _decoder = new Graphics::BitmapDecoder(); } else if (filename.hasSuffix(".tga")) { - imgDecoder = new WinterMute::TGA(); + _decoder = new WinterMute::TGA(); } else if (filename.hasSuffix(".jpg")) { - imgDecoder = new Graphics::JPEGDecoder(); + _decoder = new Graphics::JPEGDecoder(); } else { error("CBImage::loadFile : Unsupported fileformat %s", filename.c_str()); } @@ -84,9 +83,9 @@ HRESULT CBImage::loadFile(const Common::String &filename) { Common::SeekableReadStream *file = Game->_fileManager->OpenFile(filename.c_str()); if (!file) return E_FAIL; - imgDecoder->loadStream(*file); - _surface = imgDecoder->getSurface(); - _palette = imgDecoder->getPalette(); + _decoder->loadStream(*file); + _surface = _decoder->getSurface(); + _palette = _decoder->getPalette(); Game->_fileManager->CloseFile(file); return S_OK; diff --git a/engines/wintermute/Base/BSurfaceSDL.cpp b/engines/wintermute/Base/BSurfaceSDL.cpp index 8c8c6d4fb9b..ae7bad54b7f 100644 --- a/engines/wintermute/Base/BSurfaceSDL.cpp +++ b/engines/wintermute/Base/BSurfaceSDL.cpp @@ -528,7 +528,11 @@ HRESULT CBSurfaceSDL::drawSprite(int x, int y, RECT *Rect, float ZoomX, float Zo drawSrc.pixels = _scaledSurface->pixels; drawSrc.pitch = _scaledSurface->pitch; } else { - delete _scaledSurface; + if (_scaledSurface) { + _scaledSurface->free(); + delete _scaledSurface; + _scaledSurface = NULL; + } TransparentSurface src(*_surface, false); _scaledSurface = src.scale(position.width(), position.height()); drawSrc.pixels = _scaledSurface->pixels; diff --git a/engines/wintermute/video/VidTheoraPlayer.cpp b/engines/wintermute/video/VidTheoraPlayer.cpp index ca01b51d6f4..33ef8359335 100644 --- a/engines/wintermute/video/VidTheoraPlayer.cpp +++ b/engines/wintermute/video/VidTheoraPlayer.cpp @@ -74,6 +74,7 @@ void CVidTheoraPlayer::SetDefaults() { _savedState = THEORA_STATE_NONE; _savedPos = 0; _volume = 100; + _theoraDecoder = NULL; #if 0 _vorbisStreams = _theoraStreams = 0; @@ -96,6 +97,13 @@ CVidTheoraPlayer::~CVidTheoraPlayer(void) { ////////////////////////////////////////////////////////////////////////// void CVidTheoraPlayer::cleanup() { + _surface.free(); + delete _theoraDecoder; + _theoraDecoder = NULL; + delete _alphaImage; + _alphaImage = NULL; + delete _texture; + _texture = NULL; #if 0 if (m_Sound) { Game->m_SoundMgr->RemoveSound(m_Sound);