From 488bf66c3e451a65ab14a387f681fb91aa5c6253 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 19 Feb 2014 21:56:38 -0500 Subject: MADS: Fix memory leaks in MSurface --- engines/mads/msurface.cpp | 15 +++++++++++++-- engines/mads/msurface.h | 9 +++++---- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'engines/mads') diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp index e7cc08e636..f71a4a7a4e 100644 --- a/engines/mads/msurface.cpp +++ b/engines/mads/msurface.cpp @@ -51,16 +51,27 @@ MSurface *MSurface::init(int width, int height) { } } -MSurface::MSurface(bool isScreen) { +MSurface::MSurface(bool isScreen) { + pixels = nullptr; setSize(g_system->getWidth(), g_system->getHeight()); _isScreen = isScreen; } MSurface::MSurface(int width, int height) { + pixels = nullptr; setSize(width, height); _isScreen = false; } +MSurface::~MSurface() { + Graphics::Surface::free(); +} + +void MSurface::setSize(int width, int height) { + Graphics::Surface::free(); + Graphics::Surface::create(width, height, Graphics::PixelFormat::createFormatCLUT8()); +} + void MSurface::vLine(int x, int y1, int y2) { Graphics::Surface::vLine(x, y1, y2, _color); } @@ -271,7 +282,7 @@ void MSurface::drawSprite(const Common::Point &pt, SpriteInfo &info, const Commo } void MSurface::empty() { - Common::fill(getBasePtr(0, 0), getBasePtr(w, h), _vm->_palette->BLACK); + Common::fill(getBasePtr(0, 0), getBasePtr(0, h), _vm->_palette->BLACK); } void MSurface::frameRect(const Common::Rect &r, uint8 color) { diff --git a/engines/mads/msurface.h b/engines/mads/msurface.h index fe6d1f22b4..42c56e9393 100644 --- a/engines/mads/msurface.h +++ b/engines/mads/msurface.h @@ -87,14 +87,15 @@ public: */ static int scaleValue(int value, int scale, int err); public: - virtual ~MSurface() {} + /** + * Destructor + */ + virtual ~MSurface(); /** * Reinitialises a surface to have a given set of dimensions */ - void setSize(int width, int height) { - Graphics::Surface::create(width, height, Graphics::PixelFormat::createFormatCLUT8()); - } + void setSize(int width, int height); /** * Sets the color used for drawing on the surface -- cgit v1.2.3