[cairo] Possible memory leak in cairo_font_extents & cairo_text_extents

Yann Suissa yann.suissa at gmail.com
Mon May 14 16:08:56 EEST 2007


Hello everybody,

First of all i want to say that the cairo lib is really nice, i really enjoy
using it.

I often use Valgrind to check memory leaks and other issues, and i think
there could be a little something in the cairo lib.
The 2 functions that could be incriminated are cairo_font_extents &
cairo_text_extents, i didn't find any destroy/free method in the sources and
documentation.
Those 2 functions are supposed to fill structs and free all what has been
used, that's why the fact that no destroy/free methods makes sense.

Here is how i use them :

cas = cairo_xlib_surface_create(dpy, win, visual, RESX, RESY);
cr = cairo_create(cas);
[...]
cairo_font_extents(cr, &f_ext);
[...]
cairo_text_extents(cr, str, &t_ext);
[...]
cairo_destroy(cr);
cairo_surface_destroy(cas);

I use TTF fonts i think it uses the freetype lib.

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)

Thanks in advance to help
Yann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cairographics.org/archives/cairo/attachments/20070514/a6e83bd4/attachment.htm 


More information about the cairo mailing list