summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-01-20 06:55:59 +0100
committerGitHub <noreply@github.com>2020-01-20 06:55:59 +0100
commit5dddfa7b4fd03fbd688cf48605cb9d7bf818a3ee (patch)
treed05cd528bace776483ab162e2683df386bb04b8f
parent9b9ac2420f3286644d200aba7b4cd26c5ad7c8bb (diff)
parent0eab15a5a9a889e73a3f919098a92f3a0b8a043f (diff)
Merge pull request #35342 from timothyqiu/dyfont-leak
Destroys FreeType library on load error
-rw-r--r--scene/resources/dynamic_font.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp
index 8b619345d6..a21015f872 100644
--- a/scene/resources/dynamic_font.cpp
+++ b/scene/resources/dynamic_font.cpp
@@ -130,7 +130,10 @@ Error DynamicFontAtSize::_load() {
} else {
FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ);
- ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'.");
+ if (!f) {
+ FT_Done_FreeType(library);
+ ERR_FAIL_V_MSG(ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'.");
+ }
size_t len = f->get_len();
_fontdata[font->font_path] = Vector<uint8_t>();
@@ -145,7 +148,10 @@ Error DynamicFontAtSize::_load() {
if (font->font_mem == NULL && font->font_path != String()) {
FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ);
- ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'.");
+ if (!f) {
+ FT_Done_FreeType(library);
+ ERR_FAIL_V_MSG(ERR_CANT_OPEN, "Cannot open font file '" + font->font_path + "'.");
+ }
memset(&stream, 0, sizeof(FT_StreamRec));
stream.base = NULL;
@@ -176,6 +182,7 @@ Error DynamicFontAtSize::_load() {
error = FT_Open_Face(library, &fargs, 0, &face);
} else {
+ FT_Done_FreeType(library);
ERR_FAIL_V_MSG(ERR_UNCONFIGURED, "DynamicFont uninitialized.");
}