From 9a3bb81337becf05c32d6638769d0438aa8f07a8 Mon Sep 17 00:00:00 2001 From: IFAKA <99131130+IFAKA@users.noreply.github.com> Date: Sun, 21 Dec 2025 03:36:59 +0100 Subject: [PATCH] fix: add NULL checks after malloc in drawBmp() (#80) ## Problem `drawBmp()` allocates two row buffers via `malloc()` but doesn't check if allocations succeed. On low memory, this causes a crash when the NULL pointers are dereferenced. ## Fix Add NULL check after both `malloc()` calls. If either fails, log error and return early. Changed `lib/GfxRenderer/GfxRenderer.cpp`. ## Test - Defensive addition only - no logic changes - Manual device testing appreciated --- lib/GfxRenderer/GfxRenderer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp index b1a98c7..a4b9369 100644 --- a/lib/GfxRenderer/GfxRenderer.cpp +++ b/lib/GfxRenderer/GfxRenderer.cpp @@ -136,6 +136,13 @@ void GfxRenderer::drawBitmap(const Bitmap& bitmap, const int x, const int y, con auto* outputRow = static_cast(malloc(outputRowSize)); auto* rowBytes = static_cast(malloc(bitmap.getRowBytes())); + if (!outputRow || !rowBytes) { + Serial.printf("[%lu] [GFX] !! Failed to allocate BMP row buffers\n", millis()); + free(outputRow); + free(rowBytes); + return; + } + for (int bmpY = 0; bmpY < bitmap.getHeight(); bmpY++) { // The BMP's (0, 0) is the bottom-left corner (if the height is positive, top-left if negative). // Screen's (0, 0) is the top-left corner.