GRAPHICS: Fix leak in managed surface

In the case of the ManagedSurface constructor from a Surface object,
_disposeAfterUse is not initialized. But more, copyFrom() sets
_disposeAfterUse to YES after allocation of buffer. And then,
after the call to copyFrom, _disposeAfterUse was set to NO, what
made the pixels buffer not freed.
This commit is contained in:
Mathias Parnaudeau 2021-05-05 15:17:24 +02:00 committed by Filippos Karapetis
parent 032d030060
commit deefffd983
2 changed files with 4 additions and 4 deletions

View File

@ -101,8 +101,8 @@ ManagedSurface::ManagedSurface(const Surface *surf) :
return;
}
copyFrom(*surf);
_disposeAfterUse = DisposeAfterUse::NO;
copyFrom(*surf);
}
ManagedSurface::~ManagedSurface() {

View File

@ -136,7 +136,7 @@ public:
/**
* Create a managed surface from plain Surface.
*
* If disiposeAgter use flag is set (default), the surface will reuse all structures
* If disposeAfterUse flag is set (default), the surface will reuse all structures
* from the surface and destroy it, otherwise it will make a copy.
*/
ManagedSurface(Surface *surf, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
@ -161,7 +161,7 @@ public:
operator const Surface &() const { return _innerSurface; }
/**
* Return the underyling Graphics::Surface
* Return the underlying Graphics::Surface
*
* If a caller uses the non-const surfacePtr version and changes
* the surface, they'll be responsible for calling addDirtyRect
@ -610,7 +610,7 @@ public:
* @param dstFormat The desired format.
* @param palette The palette (in RGB888), if the source format has a bpp of 1.
*/
void convertToInPlace(const PixelFormat &dstFormat, const byte *palette = 0) {
void convertToInPlace(const PixelFormat &dstFormat, const byte *palette = nullptr) {
_innerSurface.convertToInPlace(dstFormat, palette);
}