From c0830ae02e2a7e881f2bdedcdc6f106c885e284b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Fri, 25 Dec 2015 19:30:23 +0100 Subject: [PATCH] Fix memory leaks in font selection for Linux Add some logging too, in particular warning when no font was found. --- distribution/changelog.txt | 1 + src/platform/linux.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 9e01dd71f8..b5d1f453c7 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -3,6 +3,7 @@ - Feature: Add displaying of frames per second (FPS). - Feature: Changing the number of trains no longer requires retesting. - Feature: Add SI units as a new measurement system for distance / speed. +- Feature: Update alternative font selection mechanism for all platforms. - Fix: [#2126] Ferris Wheels set to "backward rotation" stop working (original bug) - Fix: [#2449] Turning off Day/Night Circle while it is night doesn't reset back to day diff --git a/src/platform/linux.c b/src/platform/linux.c index 13d5244c61..22e3245fcb 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -166,7 +166,17 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer) { + assert(buffer != NULL); + assert(font != NULL); + + log_verbose("Looking for font %s with FontConfig.", font->font_name); FcConfig* config = FcInitLoadConfigAndFonts(); + if (!config) + { + log_error("Failed to initialize FontConfig library"); + FcFini(); + return false; + } FcPattern* pat = FcNameParse((const FcChar8*) font->font_name); FcConfigSubstitute(config, pat, FcMatchPattern); @@ -182,12 +192,17 @@ bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer) if (FcPatternGetString(match, FC_FILE, 0, &filename) == FcResultMatch) { found = true; - strcpy(buffer, (utf8*) filename); + safe_strncpy(buffer, (utf8*) filename, MAX_PATH); + log_verbose("FontConfig provided font %s", filename); } FcPatternDestroy(match); + } else { + log_warning("Failed to find required font."); } FcPatternDestroy(pat); + FcConfigDestroy(config); + FcFini(); return found; }