[cairo] memory leak in cairo_stroke
Benjamin Berg
benjamin at sipsolutions.net
Thu Mar 1 12:46:26 PST 2007
On Sun, 2007-18-02 at 19:07 -0500, Jeff Muizelaar wrote:
> On Sun, Feb 18, 2007 at 11:39:56PM +0100, Benjamin Berg wrote:
> > [...]
> >
> > 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.
OK, more about when the leak happens. The following lines of code leak
(line width is 1.0):
cairo_move_to (cr, 0.5, 0.5);
cairo_line_to (cr, 10.5, 0.5);
cairo_line_to (cr, 0.5, 10.5);
cairo_stroke (cr);
All the points are pixel aligned. Same for the first line segment, which
is just horizontal, but the second segment does not fit into the pixel
grid.
If one changes the example slightly, so that the first line segment is
not horizontal, then no leak occurs:
cairo_move_to (cr, 0.5, 0.5);
cairo_line_to (cr, 10.5, 10.5);
cairo_line_to (cr, 0.5, 10.5);
cairo_stroke (cr);
That said, the following patch shuts up valgrind for me. But I have no
idea if this is correct or maybe just hides something else.
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 958b95a..8b81373 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -1282,16 +1282,12 @@ _cairo_path_fixed_stroke_rectilinear (cairo_path_fixed_t *path,
NULL,
_cairo_rectilinear_stroker_close_path,
&rectilinear_stroker);
- if (status) {
- _cairo_traps_fini (traps);
- return status;
- }
+ if (status)
+ goto BAIL;
status = _cairo_rectilinear_stroker_emit_segments (&rectilinear_stroker);
- if (status)
- return status;
+BAIL:
_cairo_rectilinear_stroker_fini (&rectilinear_stroker);
-
- return CAIRO_STATUS_SUCCESS;
+ return status;
}
More information about the cairo
mailing list