From 00d95c07b80f70e22649391fea68662f9e33f40a Mon Sep 17 00:00:00 2001 From: Ross Metcalfe Date: Wed, 26 Aug 2026 18:25:05 +0100 Subject: [PATCH] Fix memory leak in rtext LoadFontFromImage method Fix for [rtext] Memory leak at LoadFontFromImage when failing to compute spacing's --- src/rtext.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index 7e30cb434..3aa0516e8 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -438,8 +438,11 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break; } - if ((x == 0) || (y == 0)) return font; // Security check - + if ((x == 0) || (y == 0)) { + UnloadImageColors(pixels); // Unload pixel colors to prevent memory leak + return font; // Security check + } + charSpacing = x; lineSpacing = y; @@ -524,7 +527,8 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) } UnloadImage(fontClear); // Unload processed image once converted to texture - + UnloadImageColors(pixels); // Unload pixel colors to prevent memory leak + font.baseSize = (int)font.recs[0].height; return font;