diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2008-08-22 07:01:35 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2008-08-22 07:01:35 +0000 |
commit | d8b4b188b676b9cdb3f33a599fc2a77051c6938c (patch) | |
tree | 2de7ef235a30da00f5025d1a4c3d2e12966f0c37 /pango/pangocairo-font.c | |
parent | 10405497c1479fd0366458c76e5036ae5e947abb (diff) | |
download | pango-d8b4b188b676b9cdb3f33a599fc2a77051c6938c.tar.gz |
Bug 143542 – PangoFT2Fontmap leak
2008-08-22 Behdad Esfahbod <behdad@gnome.org>
Bug 143542 – PangoFT2Fontmap leak
* pango/fonts.c:
* pango/pangoatsui.c (pango_atsui_font_finalize),
(_pango_atsui_font_set_font_map):
* pango/pangocairo-font.c (_pango_cairo_font_get_metrics),
(_pango_cairo_font_private_get_hex_box_info):
* pango/pangocairo-win32font.c (_pango_cairo_win32_font_new):
* pango/pangofc-font.c (pango_fc_font_get_metrics):
* pango/pangofc-fontmap.c (pango_fc_font_map_add),
(_pango_fc_font_map_remove), (cleanup_font):
* pango/pangowin32-fontmap.c (pango_win32_font_neww),
(pango_win32_font_map_real_find_font):
* pango/pangowin32.c (pango_win32_font_finalize):
* pango/pangox-fontmap.c (pango_x_font_map_load_font):
* pango/pangox.c (pango_x_font_new), (pango_x_font_finalize):
Make the reference the font->fontmap reference weak.
The code for setting the reference must look like this:
g_assert (font->fontmap == NULL);
font->fontmap = (PangoFontMap *) fontmap;
g_object_add_weak_pointer (G_OBJECT (font->fontmap), (gpointer *) (gpointer) &font->fontmap);
And releasing it like:
g_assert (font->fontmap != NULL);
g_object_remove_weak_pointer (G_OBJECT (font->fontmap), (gpointer *) (gpointer) &font->fontmap);
font->fontmap = NULL;
I have converted all fontmaps. The win32 and atsui ones can
use some simple testing.
The PangoFc fonts actually don't need the weakref as the fontmap
already provides a similar link by itself.
svn path=/trunk/; revision=2704
Diffstat (limited to 'pango/pangocairo-font.c')
-rw-r--r-- | pango/pangocairo-font.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index 0ce3cafc..15757eee 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -223,17 +223,24 @@ _pango_cairo_font_get_metrics (PangoFont *font, if (!tmp_list) { + PangoFontMap *fontmap; PangoContext *context; cairo_font_options_t *font_options; int height, shift; + /* XXX this is racy. need a ref'ing getter... */ + fontmap = pango_font_get_font_map (font); + if (!fontmap) + return pango_font_metrics_new (); + fontmap = g_object_ref (fontmap); + info = g_slice_new0 (PangoCairoFontMetricsInfo); cf_priv->metrics_by_lang = g_slist_prepend (cf_priv->metrics_by_lang, info); info->sample_str = sample_str; - context = pango_font_map_create_context (pango_font_get_font_map (font)); + context = pango_font_map_create_context (fontmap); pango_context_set_language (context, language); font_options = cairo_font_options_create (); cairo_scaled_font_get_font_options (_pango_cairo_font_private_get_scaled_font (cf_priv), font_options); @@ -271,6 +278,7 @@ _pango_cairo_font_get_metrics (PangoFont *font, info->metrics->ascent = height - info->metrics->descent; g_object_unref (context); + g_object_unref (fontmap); } return pango_font_metrics_ref (info->metrics); @@ -356,10 +364,14 @@ _pango_cairo_font_private_get_hex_box_info (PangoCairoFontPrivate *cf_priv) /* create mini_font description */ { - PangoContext *context; PangoFontMap *fontmap; + PangoContext *context; + /* XXX this is racy. need a ref'ing getter... */ fontmap = pango_font_get_font_map ((PangoFont *)cf_priv->cfont); + if (!fontmap) + return NULL; + fontmap = g_object_ref (fontmap); /* we inherit most font properties for the mini font. just * change family and size. means, you get bold hex digits @@ -396,6 +408,7 @@ _pango_cairo_font_private_get_hex_box_info (PangoCairoFontPrivate *cf_priv) mini_font = pango_font_map_load_font (fontmap, context, desc); g_object_unref (context); + g_object_unref (fontmap); } pango_font_description_free (desc); |