Corrected possible memory leak

This commit is contained in:
raysan5 2018-05-21 18:57:54 +02:00
parent 44181baf04
commit 559b9b8cc3

View File

@ -311,6 +311,7 @@ Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontCha
{
Font spriteFont = { 0 };
int totalChars = 95; // Default charset [32..126]
bool fontCharsLoaded = false;
#if defined(SUPPORT_FILEFORMAT_TTF)
if (IsFileExtension(fileName, ".ttf"))
@ -321,9 +322,12 @@ Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontCha
{
fontChars = (int *)malloc(totalChars*sizeof(int));
for (int i = 0; i < totalChars; i++) fontChars[i] = i + 32; // Default first character: SPACE[32]
fontCharsLoaded = true;
}
spriteFont = LoadTTF(fileName, fontSize, totalChars, fontChars);
if (fontCharsLoaded) free(fontChars);
}
#endif