[cairo] memory leak in cairo_stroke

Jeff Muizelaar jeff at infidigm.net
Sun Feb 18 16:07:43 PST 2007


On Sun, Feb 18, 2007 at 11:39:56PM +0100, Benjamin Berg wrote:
> Hello,
> 
> Valgrind is reporting leaks in cairo when testing some GTK engines. For
> example:
> 
> ==19020== 40,896 bytes in 639 blocks are definitely lost in loss record 3,485 of 3,485
> ==19020==    at 0xFFBAC70: malloc (vg_replace_malloc.c:149)
> ==19020==    by 0xFFBAD2C: realloc (vg_replace_malloc.c:306)
> ==19020==    by 0xF9687A4: _cairo_rectilinear_stroker_line_to (cairo-path-stroke.c:1054)
> ==19020==    by 0xF967790: _cairo_path_fixed_interpret (cairo-path-fixed.c:575)
> ==19020==    by 0xF9693E0: _cairo_path_fixed_stroke_to_traps (cairo-path-stroke.c:1283)
> ==19020==    by 0xF9736E0: _cairo_surface_fallback_stroke (cairo-surface-fallback.c:791)
> ==19020==    by 0xF970C84: _cairo_surface_stroke (cairo-surface.c:1382)
> ==19020==    by 0xF961608: _cairo_gstate_stroke (cairo-gstate.c:932)
> ==19020==    by 0xF958594: cairo_stroke_preserve (cairo.c:1906)
> ==19020==    by 0xF013994: do_redmond_draw_arrow (redmond_gtk2_misc.c:286)
> ==19020==    by 0xF0159BC: redmond_draw_arrow (redmond_gtk2_drawing.c:444)
> ==19020==    by 0xFDC15E0: gtk_paint_arrow (gtkstyle.c:5770)
> ==19020==    by 0x100029BC: main (torturetest.c:346)
> 
> It looks like the problem is that _cairo_path_fixed_stroke_rectilinear
> (cairo-path-stroke.c) only calls _cairo_rectilinear_stroker_fini on
> success.

It would be more interesting to know why
_cairo_path_fixed_interpret or _cairo_rectilinear_stroker_emit_segments
fails.

On a side note, it would be nice if this was easier to do in cairo.
Unfortunately, the places where errors actually happen are not marked
in anyway. This would be much easier if we had something like this:

if (new_segments == NULL)
	return _cairo_gen_error(CAIRO_STATUS_NO_MEMORY);

instead of:

if (new_segments == NULL)
	return CAIRO_STATUS_NO_MEMORY;

This could also make it easier to do fault injection. Cairo could
probably use better testing coverage of its error handling paths.

-Jeff


More information about the cairo mailing list