From b08f1cf79b57078352122c39e48de88e11c1fd7c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 18 Mar 2025 07:50:13 +0100 Subject: [PATCH] Fix: Fix leak when image loading failes --- src/widgets.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/widgets.cpp b/src/widgets.cpp index b6424d0..ce398c3 100644 --- a/src/widgets.cpp +++ b/src/widgets.cpp @@ -56,18 +56,15 @@ static Image *loadIntoImageCache(Context &ctx, const char *filename) { return image; } - image = new Image; - if (image == nullptr) { - return nullptr; - } - - int w, h, bytesPerPixel; + int w = 0; + int h = 0; + int bytesPerPixel = 0; unsigned char *data = stbi_load(filename, &w, &h, &bytesPerPixel, 0); if (data == nullptr) { return nullptr; } - - + + image = new Image; int pitch = w * bytesPerPixel; pitch = (pitch + 3) & ~3; image->mSurfaceImpl = Renderer::createSurfaceImpl(data, w, h, bytesPerPixel, pitch);