From cc917882a69a1d670b5e23d23a496bc2ad9da62b Mon Sep 17 00:00:00 2001 From: Aaryaman Vasishta Date: Fri, 30 Dec 2016 22:50:41 +0900 Subject: [PATCH] FULLPIPE: Fix leaks in surface and bitmap usage. Fixes part of bug #9654. --- engines/fullpipe/gfx.cpp | 10 ++++++---- engines/fullpipe/gfx.h | 1 + engines/fullpipe/statics.cpp | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/engines/fullpipe/gfx.cpp b/engines/fullpipe/gfx.cpp index ea07621cd413..619f41d6dace 100644 --- a/engines/fullpipe/gfx.cpp +++ b/engines/fullpipe/gfx.cpp @@ -479,7 +479,7 @@ void Picture::freePicture() { if (_bitmap) { if (testFlags() && !_field_54) { freeData(); - //free(_bitmap); + free(_bitmap); _bitmap = 0; } } @@ -772,6 +772,7 @@ Bitmap::Bitmap() { _flags = 0; _surface = 0; _flipping = Graphics::FLIP_NONE; + _copied_surface = false; } Bitmap::Bitmap(Bitmap *src) { @@ -784,15 +785,16 @@ Bitmap::Bitmap(Bitmap *src) { _height = src->_height; _pixels = src->_pixels; _surface = new Graphics::TransparentSurface(*src->_surface); + _copied_surface = true; _flipping = src->_flipping; } Bitmap::~Bitmap() { - if (_pixels) - free(_pixels); - _surface->free(); + if (!_copied_surface) + _surface->free(); delete _surface; + _surface = 0; _pixels = 0; } diff --git a/engines/fullpipe/gfx.h b/engines/fullpipe/gfx.h index 1b4b4d3cef34..43c23b49bc9b 100644 --- a/engines/fullpipe/gfx.h +++ b/engines/fullpipe/gfx.h @@ -45,6 +45,7 @@ struct Bitmap { int _flags; Graphics::TransparentSurface *_surface; int _flipping; + bool _copied_surface; Bitmap(); Bitmap(Bitmap *src); diff --git a/engines/fullpipe/statics.cpp b/engines/fullpipe/statics.cpp index ece4f43e9f6e..bc66ebf40be0 100644 --- a/engines/fullpipe/statics.cpp +++ b/engines/fullpipe/statics.cpp @@ -552,6 +552,8 @@ void Movement::draw(bool flipFlag, int angle) { } else { bmp->putDib(x, y, (int32 *)_currDynamicPhase->_paletteData, _currDynamicPhase->_alpha); } + //Prevent memory leak after new was used to create bmp in reverseImage() + delete bmp; if (_currDynamicPhase->_rect->top) { if (!_currDynamicPhase->_convertedBitmap) {