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
This commit is contained in:
Filippos Karapetis 2021-11-14 13:33:25 +02:00
parent 53570db898
commit 1a36cda90f
2 changed files with 6 additions and 5 deletions

View File

@ -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) {

View File

@ -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
}