[cairo] Possible memory leak in cairo_font_extents & cairo_text_extents

Chris Wilson chris at chris-wilson.co.uk
Mon May 14 16:25:00 EEST 2007


Yann Suissa (yann.suissa at gmail.com) said: 
> Here is what Valgrind says after execution :
> ==28357== 12 bytes in 1 blocks are still reachable in loss record 1 of 2
> ==28357==    at 0x4019854: malloc (vg_replace_malloc.c:149)
> ==28357==    by 0x41AA428: _cairo_ft_unscaled_font_map_create (
> cairo-ft-font.c:178)
> ==28357==    by 0x41AA5F4: _cairo_ft_unscaled_font_map_lock (cairo-ft-font.c
> :254)
> ==28357==    by 0x41AA8DD: _cairo_ft_unscaled_font_create_for_pattern (
> cairo-ft-font.c:406)
> ==28357==    by 0x41AC7F0: _cairo_ft_scaled_font_create_toy (cairo-ft-font.c
> :1600)
> ==28357==    by 0x41922AC: _cairo_toy_font_face_scaled_font_create (
> cairo-font-face.c:459)
> ==28357==    by 0x419C767: cairo_scaled_font_create (cairo-scaled-font.c
> :530)
> ==28357==    by 0x41942C5: _cairo_gstate_ensure_scaled_font (cairo-gstate.c
> :1447)
> ==28357==    by 0x419430F: _cairo_gstate_get_font_extents (cairo-gstate.c
> :1464)
> ==28357==    by 0x418D3BC: cairo_font_extents (cairo.c:2495)
> ==28357==    by 0x8054734: dt_create (obj_drawtext.c:401)
> 
> ==28357== 292 bytes in 1 blocks are still reachable in loss record 2 of 2
> ==28357==    at 0x401AC64: calloc (vg_replace_malloc.c:279)
> ==28357==    by 0x4194B40: _cairo_hash_table_resize (cairo-hash.c:330)
> ==28357==    by 0x4194DC1: _cairo_hash_table_insert (cairo-hash.c:483)
> ==28357==    by 0x4190942: _cairo_cache_insert (cairo-cache.c:307)
> ==28357==    by 0x419DEA1: _cairo_scaled_glyph_lookup (cairo-scaled-font.c
> :1527)
> ==28357==    by 0x419CEEE: _cairo_scaled_font_text_to_glyphs (
> cairo-scaled-font.c:930)
> ==28357==    by 0x4194391: _cairo_gstate_text_to_glyphs (cairo-gstate.c
> :1487)
> ==28357==    by 0x418D71A: cairo_text_extents (cairo.c:2794)
> ==28357==    by 0x8053C3D: dt_fill_multi_line_count (obj_drawtext.c:152)

This pair of leaks is due to the static allocation of font and glyph
caches. Cairo uses many such behind-the-scenes caches and provides
cairo_debug_reset_static_data() which should free all of Cairo's
statically allocated memory. Please note the warnings in the function's
documentation and only use it during program finalisation if you are
performing leak checking. Also note that a few of Cairo's dependent
libraries also maintain their own caches and provide their own methods
for releasing their memory during finalisation, e.g. FcFini().
--
Chris Wilson


More information about the cairo mailing list