[cairo] Memory leak in text functions?

Jan Slupski jslupski at juljas.net
Mon May 22 08:07:16 PDT 2006


Hi,

I'm using Cairo to create image surface, and when trying to 
use any text related function (eg. cairo_text_extents),
I'm observing quite big memory leak.

I've searched the archives, and couldn't find anything related.
Is it possible that I did something wrong (eg. with compilation)?

I've tried Cairo 1.0.4, as well as today's git version.

The leak is detected by valgrind tool in text.c from 
cairo-demo package, as well as in following tiny example:

#include <cairo.h>
#include <stdio.h>

int main (int argc, char *argv[]) {
   cairo_surface_t *surface;
   cairo_t *cr;
   cairo_text_extents_t size;

   surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 800, 600);
   cr = cairo_create (surface);

   cairo_text_extents(cr, "Hello", &size);
   printf("size: %.2fx%.2f advance x: %.2f y: %.2f bearing x: %.2f y: %.2f\n",size.width,size.height,size.x_advance,size.y_advance, size.x_bearing, size.y_bearing);
   cairo_destroy (cr);
   cairo_surface_destroy (surface);
   return 0;
}


Valgrind output:

$ valgrind ./extents
(...)
==5296== 12 bytes in 1 blocks are still reachable in loss record 1 of 39
==5296==    at 0x400444E: malloc (vg_replace_malloc.c:149)
==5296==    by 0x4026587: _cairo_ft_unscaled_font_map_lock (cairo-ft-font.c:173)
==5296==    by 0x40267E3: _cairo_ft_unscaled_font_create_for_pattern (cairo-ft-f ont.c:398)
==5296==    by 0x4028002: _cairo_ft_scaled_font_create_toy (cairo-ft-font.c:1556 )
==5296==    by 0x4013DE3: _cairo_toy_font_face_scaled_font_create (cairo-font.c: 419)
==5296==    by 0x401BCC8: cairo_scaled_font_create (cairo-scaled-font.c:439)
==5296==    by 0x4015776: _cairo_gstate_ensure_scaled_font (cairo-gstate.c:1378)
==5296==    by 0x40157E3: _cairo_gstate_text_to_glyphs (cairo-gstate.c:1412)
==5296==    by 0x4011905: cairo_text_extents (cairo.c:2302)
==5296==    by 0x8048985: main (in /home/follow/c/cairo/extents)
(...)
==5296== LEAK SUMMARY:
==5296==    definitely lost: 0 bytes in 0 blocks.
==5296==      possibly lost: 0 bytes in 0 blocks.
==5296==    still reachable: 359,238 bytes in 2,145 blocks.
==5296==         suppressed: 0 bytes in 0 blocks.


Please let me know in case you need any more information.

Thanks,
Jan Slupski


    _  _  _  _  _____________________________________________
    | |_| |\ |  S L U P S K I             jslupski at juljas.net
  |_| | | | \|                             http://juljas.net/


More information about the cairo mailing list