From 152a862f5079dc69c8c5557b42a98fcf2cf06c74 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 30 Dec 2018 23:25:31 +1100 Subject: [PATCH] Fix memory leak of fonts, reduces memory usage by 3-5 MB. Also fix caret not showing in servers list menu --- src/LScreens.c | 4 +++- src/Platform.c | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/LScreens.c b/src/LScreens.c index ee32bf28f..582e14102 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -1235,8 +1235,10 @@ static void ServersScreen_Tick(struct LScreen* s_) { const static String refresh = String_FromConst("Refresh"); const static String failed = String_FromConst("&cFailed"); struct ServersScreen* s = (struct ServersScreen*)s_; + int count; + LScreen_Tick(s_); - int count = FetchFlagsTask.Count; + count = FetchFlagsTask.Count; LWebTask_Tick(&FetchFlagsTask.Base); /* TODO: Only redraw flags */ if (count != FetchFlagsTask.Count) LWidget_Draw(&s->Table); diff --git a/src/Platform.c b/src/Platform.c index 1aadf40c9..59f8d2dee 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -990,6 +990,16 @@ static void Font_DirCallback(const String* path, void* obj) { FT_Error err; int i, flags; + /* Completely skip windows .FON files */ + if (String_CaselessEnds(path, &fonExt)) return; + + /* If font is already known good, skip it */ + for (i = 0; i < font_list.Entries.Count; i++) { + entry = StringsBuffer_UNSAFE_Get(&font_list.Entries, i); + String_UNSAFE_Separate(&entry, font_list.Separator, &name, &fontPath); + if (String_CaselessEquals(path, &fontPath)) return; + } + if (!Font_MakeArgs(path, &stream, &args)) return; /* For OSX font suitcase files */ @@ -1001,16 +1011,6 @@ static void Font_DirCallback(const String* path, void* obj) { args.pathname = filename.buffer; #endif - /* If font is already known good, skip it */ - for (i = 0; i < font_list.Entries.Count; i++) { - entry = StringsBuffer_UNSAFE_Get(&font_list.Entries, i); - String_UNSAFE_Separate(&entry, font_list.Separator, &name, &fontPath); - if (String_CaselessEquals(path, &fontPath)) return; - } - - /* Completely skip windows .FON files */ - if (String_CaselessEnds(path, &fonExt)) return; - err = FT_New_Face(ft_lib, &args, 0, &face); if (err) { stream.close(&stream); return; } flags = face->style_flags;