[Scummvm-git-logs] scummvm master -> 3e5fbad9052138d8c3523eb6d6f71d7cdab4e992
bluegr
noreply at scummvm.org
Tue May 20 05:33:11 UTC 2025
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
db7511721f GRAPHICS: Fix memory leaks in image archive
3e5fbad905 GRAPHICS: Properly delete loaded stream
Commit: db7511721ff43581a874c4ea84d494183aff40fb
https://github.com/scummvm/scummvm/commit/db7511721ff43581a874c4ea84d494183aff40fb
Author: Åukasz Lenkiewicz (lukasz at lenkiewicz.xyz)
Date: 2025-05-20T08:33:08+03:00
Commit Message:
GRAPHICS: Fix memory leaks in image archive
1. Surface stored in _imageCache[fname] needs to be explicitly freed as stated in
Graphics::Surface *Surface::scale documentation.
2. Common::SeekableReadStream *stream needs to be properly deleted, so additional
includes were added.
Changed paths:
graphics/image-archive.cpp
diff --git a/graphics/image-archive.cpp b/graphics/image-archive.cpp
index 298d03be796..abc0f5aaa6e 100644
--- a/graphics/image-archive.cpp
+++ b/graphics/image-archive.cpp
@@ -20,6 +20,7 @@
*/
#include "graphics/image-archive.h"
+#include "common/stream.h"
#include "graphics/surface.h"
#include "common/archive.h"
@@ -37,8 +38,10 @@ ImageArchive::~ImageArchive() {
void ImageArchive::reset() {
#ifdef USE_PNG
- for (auto &i : _imageCache)
+ for (auto &i : _imageCache) {
+ i._value->free();
delete i._value;
+ }
_imageCache.clear();
#endif
}
@@ -87,12 +90,16 @@ const Surface *ImageArchive::getImageSurface(const Common::Path &fname, int w, i
}
if (_imageCache.contains(fname)) {
+ // Surface was created by scale(), it needs to be freed explicitly
+ _imageCache[fname]->free();
delete _imageCache[fname];
_imageCache.erase(fname);
}
const Graphics::Surface *surf = decoder.getSurface();
_imageCache[fname] = surf->scale(w ? w : surf->w, h ? h : surf->h, true);
+
+ delete stream;
return _imageCache[fname];
#endif // USE_PNG
}
Commit: 3e5fbad9052138d8c3523eb6d6f71d7cdab4e992
https://github.com/scummvm/scummvm/commit/3e5fbad9052138d8c3523eb6d6f71d7cdab4e992
Author: Åukasz Lenkiewicz (lukasz at lenkiewicz.xyz)
Date: 2025-05-20T08:33:08+03:00
Commit Message:
GRAPHICS: Properly delete loaded stream
Changed paths:
graphics/image-archive.cpp
diff --git a/graphics/image-archive.cpp b/graphics/image-archive.cpp
index abc0f5aaa6e..235e0d7bf6c 100644
--- a/graphics/image-archive.cpp
+++ b/graphics/image-archive.cpp
@@ -83,7 +83,11 @@ const Surface *ImageArchive::getImageSurface(const Common::Path &fname, int w, i
}
Image::PNGDecoder decoder;
- if (!decoder.loadStream(*stream)) {
+
+ bool result = decoder.loadStream(*stream);
+ delete stream;
+
+ if (!result) {
warning("ImageArchive::getImageSurface(): Cannot load file %s", fname.toString().c_str());
return _imageCache[fname];
@@ -99,7 +103,6 @@ const Surface *ImageArchive::getImageSurface(const Common::Path &fname, int w, i
const Graphics::Surface *surf = decoder.getSurface();
_imageCache[fname] = surf->scale(w ? w : surf->w, h ? h : surf->h, true);
- delete stream;
return _imageCache[fname];
#endif // USE_PNG
}
More information about the Scummvm-git-logs
mailing list