GUI: Fix leak of ManagedSurface in PicButtonWidget

Opening the load dialog, to display thumbnails into PicButtonWidget objects,
a call to setGfx creates a temporary ManagedSurface from a Surface but is
not instantiated, so not freed.

Same fix applied in GraphicsWidget which code is the same and reported
as potential memory leak by clang-tidy.
This commit is contained in:
Mathias Parnaudeau 2021-05-12 09:41:53 +02:00 committed by Eugene Sandulenko
parent 59c9d26963
commit 032d030060

View File

@ -610,7 +610,9 @@ void PicButtonWidget::setGfx(const Graphics::ManagedSurface *gfx, int statenum,
}
void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum, bool scale) {
setGfx(new Graphics::ManagedSurface(gfx), statenum, scale);
const Graphics::ManagedSurface *tmpGfx = new Graphics::ManagedSurface(gfx);
setGfx(tmpGfx, statenum, scale);
delete tmpGfx;
}
void PicButtonWidget::setGfxFromTheme(const char *name, int statenum, bool scale) {
@ -898,7 +900,9 @@ void GraphicsWidget::setGfx(const Graphics::ManagedSurface *gfx, bool scale) {
}
void GraphicsWidget::setGfx(const Graphics::Surface *gfx, bool scale) {
setGfx(new Graphics::ManagedSurface(gfx), scale);
const Graphics::ManagedSurface *tmpGfx = new Graphics::ManagedSurface(gfx);
setGfx(tmpGfx, scale);
delete tmpGfx;
}
void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {