From 744dc2218208790535ff26aad4d07c88026dc63d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 24 Feb 2021 15:10:09 -0500 Subject: fc: Fix an ordering issue With the recently introduced threading for fontconfig calls, we introduced an ordering issue where the fontmap may die before an outstanding thread returns, and then the code that unrefs the pattern object tries to remove it from the fontmap cache. Prevent that by giving each thread a strong ref on the fontmap while it runs. Fixes: #537 --- pango/pangofc-fontmap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index aa90345e..fef3394a 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -800,6 +800,10 @@ static ThreadData * thread_data_new (PangoFcPatterns *patterns) { ThreadData *td; + PangoFcFontMap *fontmap = patterns->fontmap; + + /* We don't want the fontmap dying on us */ + g_object_ref (fontmap); td = g_new (ThreadData, 1); td->patterns = pango_fc_patterns_ref (patterns); @@ -814,12 +818,15 @@ static void thread_data_free (gpointer data) { ThreadData *td = data; + PangoFcFontMap *fontmap = td->patterns->fontmap; g_clear_pointer (&td->fonts, FcFontSetDestroy); FcPatternDestroy (td->pattern); FcConfigDestroy (td->config); pango_fc_patterns_unref (td->patterns); g_free (td); + + g_object_unref (fontmap); } static void -- cgit v1.2.1