[Scummvm-git-logs] scummvm master -> 1a36cda90f280ac3fd844e64b85277d5d2ec781c

bluegr noreply at scummvm.org
Sun Nov 14 11:33:58 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1a36cda90f NGI: Plug memory leaks - bug #13071


Commit: 1a36cda90f280ac3fd844e64b85277d5d2ec781c
    https://github.com/scummvm/scummvm/commit/1a36cda90f280ac3fd844e64b85277d5d2ec781c
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2021-11-14T13:33:41+02:00

Commit Message:
NGI: Plug memory leaks - bug #13071

Create a new instance of a TransparentSurface in Bitmap's copy
constructor, instead of holding a reference to the original
TransparentSurface. This allows to gracefully delete Bitmap's
TransparentSurface when an instance of Bitmap is destroyed and
resolves the memory leaks when changing rooms

Changed paths:
    engines/ngi/gfx.cpp
    engines/ngi/utils.cpp


diff --git a/engines/ngi/gfx.cpp b/engines/ngi/gfx.cpp
index 21d05170ea..82aeefead9 100644
--- a/engines/ngi/gfx.cpp
+++ b/engines/ngi/gfx.cpp
@@ -708,15 +708,15 @@ Bitmap::Bitmap(const Bitmap &src) {
 	_type = src._type;
 	_width = src._width;
 	_height = src._height;
-	_surface = src._surface;
 	_flipping = src._flipping;
-	_surface = src._surface;
+	_surface = new Graphics::TransparentSurface, Graphics::SurfaceDeleter();
+	_surface->create(_width, _height, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
+	_surface->copyFrom(*src._surface);
 }
 
 Bitmap::~Bitmap() {
-	// TODO: This is a hack because Graphics::Surface has terrible resource
-	// management
-	//_surface->free();
+	_surface->free();
+	delete _surface;
 }
 
 void Bitmap::load(Common::ReadStream *s) {
diff --git a/engines/ngi/utils.cpp b/engines/ngi/utils.cpp
index 3c27bc6ba3..de81c2dc9a 100644
--- a/engines/ngi/utils.cpp
+++ b/engines/ngi/utils.cpp
@@ -161,6 +161,7 @@ void MemoryObject::loadFile(const Common::String &filename) {
 			debugC(5, kDebugLoading, "Loading %s (%d bytes)", filename.c_str(), _dataSize);
 			_data = (byte *)calloc(_dataSize, 1);
 			s->read(_data, _dataSize);
+			delete s;
 		} else {
 			// We have no object to read. This is fine
 		}




More information about the Scummvm-git-logs mailing list