From ad2ce4a87ee545b52f92b26564efc3d84b253ed0 Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Wed, 31 Dec 2014 01:42:44 +0100 Subject: [PATCH] EMI: Fix memleaks caused by specialtyTextures - delete screenshot after texture is created - free _data[] entries in BitmapData::freeData() - destroy _specialtyTextures[] entries in graphic driver's destructors --- engines/grim/bitmap.cpp | 3 +++ engines/grim/emi/lua_v2.cpp | 5 +++-- engines/grim/gfx_opengl.cpp | 3 +++ engines/grim/gfx_opengl_shaders.cpp | 3 +++ engines/grim/gfx_tinygl.cpp | 3 +++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/engines/grim/bitmap.cpp b/engines/grim/bitmap.cpp index 1661c809c39..f163bb575cb 100644 --- a/engines/grim/bitmap.cpp +++ b/engines/grim/bitmap.cpp @@ -233,6 +233,9 @@ BitmapData::~BitmapData() { void BitmapData::freeData() { if (!_keepData) { + for (int i = 0; i < _numImages; ++i) { + _data[i].free(); + } delete[] _data; _data = nullptr; } diff --git a/engines/grim/emi/lua_v2.cpp b/engines/grim/emi/lua_v2.cpp index e7fafc9f173..4ca75cde841 100644 --- a/engines/grim/emi/lua_v2.cpp +++ b/engines/grim/emi/lua_v2.cpp @@ -480,7 +480,6 @@ void Lua_V2::ThumbnailFromFile() { const char *filename = lua_getstring(filenameObj); int width = 256, height = 128; - Bitmap *screenshot; SaveGame *savedState = SaveGame::openForLoading(filename); if (!savedState || !savedState->isCompatible()) { @@ -501,10 +500,11 @@ void Lua_V2::ThumbnailFromFile() { data[l] = savedState->readLEUint16(); } Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data); - screenshot = new Bitmap(buf, width, height, "screenshot"); + Bitmap *screenshot = new Bitmap(buf, width, height, "screenshot"); if (!screenshot) { lua_pushnil(); warning("Lua_V2::ThumbnailFromFile: Could not restore screenshot from file %s", filename); + delete screenshot; delete[] data; delete savedState; return; @@ -512,6 +512,7 @@ void Lua_V2::ThumbnailFromFile() { screenshot->_data->convertToColorFormat(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)); g_driver->createSpecialtyTexture(index, screenshot->getData(0).getRawBuffer(), width, height); + delete screenshot; delete[] data; savedState->endSection(); delete savedState; diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp index f4be2a7d321..168f410dfae 100644 --- a/engines/grim/gfx_opengl.cpp +++ b/engines/grim/gfx_opengl.cpp @@ -124,6 +124,9 @@ GfxOpenGL::~GfxOpenGL() { if (_useDimShader) glDeleteProgramsARB(1, &_dimFragProgram); #endif + for (unsigned int i = 0; i < _numSpecialtyTextures; i++) { + destroyTexture(&_specialtyTextures[i]); + } } byte *GfxOpenGL::setupScreen(int screenW, int screenH, bool fullscreen) { diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp index 6464fdf89f0..e941335568e 100644 --- a/engines/grim/gfx_opengl_shaders.cpp +++ b/engines/grim/gfx_opengl_shaders.cpp @@ -239,6 +239,9 @@ GfxOpenGLS::GfxOpenGLS() { } GfxOpenGLS::~GfxOpenGLS() { + for (unsigned int i = 0; i < _numSpecialtyTextures; i++) { + destroyTexture(&_specialtyTextures[i]); + } delete[] _lights; delete _backgroundProgram; diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index 211f6788124..ced4cb68685 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -64,6 +64,9 @@ GfxTinyGL::GfxTinyGL() : } GfxTinyGL::~GfxTinyGL() { + for (unsigned int i = 0; i < _numSpecialtyTextures; i++) { + destroyTexture(&_specialtyTextures[i]); + } if (_zb) { delBuffer(1); TinyGL::glClose();