[pango/fontmap-thread-fix] fc: Fix an ordering issue




commit 744dc2218208790535ff26aad4d07c88026dc63d
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Feb 24 15:10:09 2021 -0500

    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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]