Index: app/text/gimptextlayout.c
===================================================================
RCS file: /cvs/gnome/gimp/app/text/gimptextlayout.c,v
retrieving revision 1.21
diff -u -r1.21 gimptextlayout.c
--- app/text/gimptextlayout.c	25 Jan 2004 21:06:01 -0000	1.21
+++ app/text/gimptextlayout.c	2 Aug 2004 17:52:42 -0000
@@ -325,6 +325,17 @@
   FcPatternAddBool (pattern, FC_ANTIALIAS, text->antialias);
 }
 
+#ifndef NO_143542_WORKAROUND
+static void
+context_fontmap_destroy (PangoFT2FontMap *fontmap)
+{
+  /* This calls pango_fc_font_map_cache_clear (not part of app API) to
+     remove circular references */
+  pango_ft2_font_map_substitute_changed (fontmap);
+  g_object_unref (fontmap);
+}
+#endif
+
 static PangoContext *
 gimp_text_get_pango_context (GimpText *text,
                              gdouble   xres,
@@ -332,6 +343,11 @@
 {
   PangoContext    *context;
   PangoFT2FontMap *fontmap;
+#ifndef NO_143542_WORKAROUND
+  static GQuark fontmap_quark = 0;
+  if (!fontmap_quark)
+    fontmap_quark = g_quark_from_static_string ("gimp-fontmap-fix-143542");
+#endif
 
   fontmap = PANGO_FT2_FONT_MAP (pango_ft2_font_map_new ());
 
@@ -343,7 +359,14 @@
                                              (GDestroyNotify) g_object_unref);
 
   context = pango_ft2_font_map_create_context (fontmap);
+#ifndef NO_143542_WORKAROUND
+  /* Workaround for Pango bug #143542 - PangoFT2Fontmap leak
+     keep a reference to the fontmap around so we can clear the cache */
+  g_object_set_qdata_full (G_OBJECT (context), fontmap_quark, fontmap,
+                           (GDestroyNotify)context_fontmap_destroy);
+#else
   g_object_unref (fontmap);
+#endif
 
   if (text->language)
     pango_context_set_language (context,
