From 5d20479b99c187ee90ebce36b97a9064acff8f0d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 29 Apr 2008 09:03:00 +0100 Subject: [PATCH] [test/ft-font-create-for-ft-face] Fix the lifetime issues of FT_Face. The font_face created from cairo_ft_font_face_create_for_ft_face() was being kept alive by a reference from the context beyond the lifetime of the parent cairo_scaled_font_t (which owned the FT_Face). Correct the example in the test code to remove this errant reference before cleaning up the fonts. (To be fair, to actually trigger a bug one has to evict the FT_Face from the cache before using the font_face - merely creating a cairo_scaled_font_t for every font on the system is enough.) --- test/ft-font-create-for-ft-face.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/ft-font-create-for-ft-face.c b/test/ft-font-create-for-ft-face.c index 066b175d3..35cb77d48 100644 --- a/test/ft-font-create-for-ft-face.c +++ b/test/ft-font-create-for-ft-face.c @@ -50,7 +50,9 @@ draw (cairo_t *cr, int width, int height) /* We're trying here to get our hands on _some_ FT_Face but we do * not at all care which one. So we start with an empty pattern * and do the minimal substitution on it in order to get a valid - * pattern. */ + * pattern. + * + * Do not use this in production code! */ pattern = FcPatternCreate (); if (! pattern) { cairo_test_log ("FcPatternCreate failed.\n"); @@ -117,8 +119,10 @@ draw (cairo_t *cr, int width, int height) /* Set the font_face and force cairo to actually use it for * something. */ + cairo_save (cr); cairo_set_font_face (cr, font_face); cairo_font_extents (cr, &font_extents); + cairo_restore (cr); /* Finally, even more cleanup */ cairo_font_face_destroy (font_face);