Fix memory leak in rtext LoadFontFromImage method

Fix for
[rtext] Memory leak at LoadFontFromImage when failing to compute spacing's
This commit is contained in:
Ross Metcalfe 2026-08-26 18:25:05 +01:00 • committed by GitHub
commit 00d95c07b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;