[cairo-commit] 2 commits - src/cairo-debug.c src/cairo-image-surface.c src/cairoint.h test/linear-gradient-large.c test/nil-surface.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Thu Sep 9 08:26:24 PDT 2010


 src/cairo-debug.c            |    2 ++
 src/cairo-image-surface.c    |   42 ++++++++++++++++++++++++++++++++++--------
 src/cairoint.h               |    3 +++
 test/linear-gradient-large.c |    1 +
 test/nil-surface.c           |    3 ++-
 5 files changed, 42 insertions(+), 9 deletions(-)

New commits:
commit 8fda4ab1cc7f60196b232d194c33e592ecdec9b5
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Thu Aug 26 11:15:46 2010 +0200

    image: add _cairo_image_reset_static_data
    
    Image has static caches which needs to be reset to make
    cairo_debug_reset_static_data behave as expected.
    Silences a bunch of leak reports by check-valgrind.
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-debug.c b/src/cairo-debug.c
index 712ce93..c956753 100644
--- a/src/cairo-debug.c
+++ b/src/cairo-debug.c
@@ -77,6 +77,8 @@ cairo_debug_reset_static_data (void)
 
     _cairo_clip_reset_static_data ();
 
+    _cairo_image_reset_static_data ();
+
 #if CAIRO_HAS_DRM_SURFACE
     _cairo_drm_device_reset_static_data ();
 #endif
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index f88ccb8..4d65ee6 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -876,10 +876,13 @@ _nearest_sample (cairo_filter_t filter, double *tx, double *ty)
 }
 
 #if HAS_ATOMIC_OPS
+static pixman_image_t *__pixman_transparent_image;
+static pixman_image_t *__pixman_black_image;
+static pixman_image_t *__pixman_white_image;
+
 static pixman_image_t *
 _pixman_transparent_image (void)
 {
-    static pixman_image_t *__pixman_transparent_image;
     pixman_image_t *image;
 
     image = __pixman_transparent_image;
@@ -910,7 +913,6 @@ _pixman_transparent_image (void)
 static pixman_image_t *
 _pixman_black_image (void)
 {
-    static pixman_image_t *__pixman_black_image;
     pixman_image_t *image;
 
     image = __pixman_black_image;
@@ -941,7 +943,6 @@ _pixman_black_image (void)
 static pixman_image_t *
 _pixman_white_image (void)
 {
-    static pixman_image_t *__pixman_white_image;
     pixman_image_t *image;
 
     image = __pixman_white_image;
@@ -995,14 +996,39 @@ hars_petruska_f54_1_random (void)
 #undef rol
 }
 
+static struct {
+    cairo_color_t color;
+    pixman_image_t *image;
+} cache[16];
+static int n_cached;
+
+void
+_cairo_image_reset_static_data ()
+{
+    while (n_cached)
+	pixman_image_unref (cache[--n_cached].image);
+
+#if HAS_ATOMIC_OPS
+    if (__pixman_transparent_image) {
+	pixman_image_unref (__pixman_transparent_image);
+	__pixman_transparent_image = NULL;
+    }
+
+    if (__pixman_black_image) {
+	pixman_image_unref (__pixman_black_image);
+	__pixman_black_image = NULL;
+    }
+
+    if (__pixman_white_image) {
+	pixman_image_unref (__pixman_white_image);
+	__pixman_white_image = NULL;
+    }
+#endif
+}
+
 static pixman_image_t *
 _pixman_image_for_solid (const cairo_solid_pattern_t *pattern)
 {
-    static struct {
-	cairo_color_t color;
-	pixman_image_t *image;
-    } cache[16];
-    static int n_cached;
     pixman_color_t color;
     pixman_image_t *image;
     int i;
diff --git a/src/cairoint.h b/src/cairoint.h
index fe2f7fc..500b2d9 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1906,6 +1906,9 @@ cairo_private cairo_bool_t
 _pixman_format_to_masks (pixman_format_code_t	 pixman_format,
 			 cairo_format_masks_t	*masks);
 
+cairo_private void
+_cairo_image_reset_static_data (void);
+
 cairo_private cairo_surface_t *
 _cairo_image_surface_create_with_pixman_format (unsigned char		*data,
 						pixman_format_code_t	 pixman_format,
commit ca775cbf5a7245092cabdda43db9d06e96613ff4
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Thu Aug 26 11:13:51 2010 +0200

    test: do not leak resources
    
    Silence two leak reports by check-valgrind.
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/test/linear-gradient-large.c b/test/linear-gradient-large.c
index f5e6a66..5646aa4 100644
--- a/test/linear-gradient-large.c
+++ b/test/linear-gradient-large.c
@@ -51,6 +51,7 @@ draw (cairo_t *cr, int width, int height)
     cairo_pattern_add_color_stop_rgb (gr, 1.0, 1, 1, 1);
 
     cairo_set_source (cr, gr);
+    cairo_pattern_destroy (gr);
     cairo_paint (cr);
 
     mark_point(cr, SIZE - OFFSET, OFFSET);
diff --git a/test/nil-surface.c b/test/nil-surface.c
index 408bdba..30a1f97 100644
--- a/test/nil-surface.c
+++ b/test/nil-surface.c
@@ -154,7 +154,8 @@ draw (cairo_t *cr, int width, int height)
     /* Test that push_group doesn't crash */
     cairo_push_group (cr2);
     cairo_stroke (cr2);
-    cairo_pop_group (cr2);
+    pattern = cairo_pop_group (cr2);
+    cairo_pattern_destroy (pattern);
 
     cairo_destroy (cr2);
 


More information about the cairo-commit mailing list