From 9b27dc38947a69d2b93c9a3b6b5a707f159e9b2e Mon Sep 17 00:00:00 2001 From: Olli Wang Date: Thu, 27 Sep 2018 17:51:38 +0800 Subject: [PATCH] Fixes memory leaks of freetype. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the issue that freetype library isn’t released in `fonsDeleteInternal()` and causes memory leaks. --- src/fontstash.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/fontstash.h b/src/fontstash.h index 0021863..f2deedd 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -162,11 +162,19 @@ static FT_Library ftLibrary; int fons__tt_init(FONScontext *context) { FT_Error ftError; - FONS_NOTUSED(context); + FONS_NOTUSED(context); ftError = FT_Init_FreeType(&ftLibrary); return ftError == 0; } +int fons__tt_done(FONScontext *context) +{ + FT_Error ftError; + FONS_NOTUSED(context); + ftError = FT_Done_FreeType(ftLibrary); + return ftError == 0; +} + int fons__tt_loadFont(FONScontext *context, FONSttFontImpl *font, unsigned char *data, int dataSize) { FT_Error ftError; @@ -264,6 +272,11 @@ int fons__tt_init(FONScontext *context) return 1; } +int fons__tt_done(FONScontext *context) + FONS_NOTUSED(context); + return 1; +} + int fons__tt_loadFont(FONScontext *context, FONSttFontImpl *font, unsigned char *data, int dataSize) { int stbError; @@ -1630,6 +1643,7 @@ void fonsDeleteInternal(FONScontext* stash) if (stash->texData) free(stash->texData); if (stash->scratch) free(stash->scratch); free(stash); + fons__tt_done(stash); } void fonsSetErrorCallback(FONScontext* stash, void (*callback)(void* uptr, int error, int val), void* uptr)