From 3cd006bb2b3986aefaf6cf9002735c430e4bc172 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 14 Jul 2005 15:10:47 +0000 Subject: [PATCH] Fix to accept a cairo_pattern_t rather than a cairo_surface_t as the primary argument. Track change in _cairo_pattern_release_surface and also pass the appropriate pattern for each acquired surface. The previous backend mismatch was causing memory leaks. Remove stale comment. Add missing fclose to keep valgrind happy about memory leaks. --- ChangeLog | 19 +++++++++++++++++++ src/cairo-image-surface.c | 6 +++--- src/cairo-pattern.c | 13 +++++++++---- src/cairo-xlib-surface.c | 1 - src/cairoint.h | 2 +- test/xlib-surface.c | 4 ++++ 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index a84fe8df1..18ae14640 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-07-14 Carl Worth + + * src/cairoint.h: + * src/cairo-pattern.c: (_cairo_pattern_release_surface): Fix to + accept a cairo_pattern_t rather than a cairo_surface_t as the + primary argument. + + * src/cairo-image-surface.c: (_cairo_image_surface_composite), + (_cairo_image_surface_composite_trapezoids): Track change in + _cairo_pattern_release_surface and also pass the appropriate + pattern for each acquired surface. The previous backend mismatch + was causing memory leaks. + + * src/cairo-xlib-surface.c: (_get_image_surface): Remove stale + comment. + + * test/xlib-surface.c: (main): Add missing fclose to keep valgrind + happy about memory leaks. + 2005-07-14 Carl Worth * test/cairo-test.c: (cairo_test_expecting), diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 209ee8f04..aff35ce3c 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -595,9 +595,9 @@ _cairo_image_surface_composite (cairo_operator_t operator, } if (mask) - _cairo_pattern_release_surface (&dst->base, &mask->base, &mask_attr); + _cairo_pattern_release_surface (mask_pattern, &mask->base, &mask_attr); - _cairo_pattern_release_surface (&dst->base, &src->base, &src_attr); + _cairo_pattern_release_surface (src_pattern, &src->base, &src_attr); return status; } @@ -674,7 +674,7 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t operator, render_src_y + attributes.y_offset, (pixman_trapezoid_t *) traps, num_traps); - _cairo_pattern_release_surface (&dst->base, &src->base, &attributes); + _cairo_pattern_release_surface (pattern, &src->base, &attributes); return status; } diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 5af55bf89..9c8ddff9f 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -1409,19 +1409,24 @@ _cairo_pattern_acquire_surface (cairo_pattern_t *pattern, /** * _cairo_pattern_release_surface: * @pattern: a #cairo_pattern_t - * @info: pointer to #cairo_surface_attributes_t filled in by - * _cairo_pattern_acquire_surface + * @surface: a surface obtained by _cairo_pattern_acquire_surface + * @attributes: attributes obtained by _cairo_pattern_acquire_surface * * Releases resources obtained by _cairo_pattern_acquire_surface. **/ void -_cairo_pattern_release_surface (cairo_surface_t *dst, +_cairo_pattern_release_surface (cairo_pattern_t *pattern, cairo_surface_t *surface, cairo_surface_attributes_t *attributes) { if (attributes->acquired) { - _cairo_surface_release_source_image (dst, + cairo_surface_pattern_t *surface_pattern; + + assert (pattern->type == CAIRO_PATTERN_SURFACE); + surface_pattern = (cairo_surface_pattern_t *) pattern; + + _cairo_surface_release_source_image (surface_pattern->surface, (cairo_image_surface_t *) surface, attributes->extra); } diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index c5b26e505..88f514dbe 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -450,7 +450,6 @@ _get_image_surface (cairo_xlib_surface_t *surface, } /* Let the surface take ownership of the data */ - /* XXX: Can probably come up with a cleaner API here. */ _cairo_image_surface_assume_ownership_of_data (image); ximage->data = NULL; XDestroyImage (ximage); diff --git a/src/cairoint.h b/src/cairoint.h index a1b67f943..bd8072c5d 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -1817,7 +1817,7 @@ _cairo_pattern_acquire_surface (cairo_pattern_t *pattern, cairo_surface_attributes_t *attributes); cairo_private void -_cairo_pattern_release_surface (cairo_surface_t *dst, +_cairo_pattern_release_surface (cairo_pattern_t *pattern, cairo_surface_t *surface, cairo_surface_attributes_t *attributes); diff --git a/test/xlib-surface.c b/test/xlib-surface.c index d8c241c8e..2921eb852 100644 --- a/test/xlib-surface.c +++ b/test/xlib-surface.c @@ -221,11 +221,13 @@ main (void) dpy = XOpenDisplay (NULL); if (!dpy) { fprintf (log_file, "xlib-surface: Cannot open display, skipping\n"); + fclose (log_file); return 0; } if (!check_visual (dpy)) { fprintf (log_file, "xlib-surface: default visual is not RGB24 or BGR24, skipping\n"); + fclose (log_file); return 0; } @@ -264,6 +266,8 @@ main (void) free (diff_data); XCloseDisplay (dpy); + + fclose (log_file); return result; }