[cairo-commit] cairo/test cairo-test.c, 1.42, 1.43 trap-clip.c, 1.4, 1.5

Carl Worth commit at pdx.freedesktop.org
Thu Jul 14 16:18:41 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv7305/test

Modified Files:
	cairo-test.c trap-clip.c 
Log Message:

        * test/cairo-test.c: (cairo_test_create_png_pattern): Rewrite to
        use cairo_image_surface_create_from_png rather than custom
        read_png_argb32. In addition to being simpler, this eliminates the
        leak of the image data buffer.

        * test/trap-clip.c: (set_gradient_pattern), (set_image_pattern):
        Add calls to cairo_pattern_destroy to close two memory leaks.


Index: cairo-test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- cairo-test.c	14 Jul 2005 19:50:28 -0000	1.42
+++ cairo-test.c	14 Jul 2005 23:18:39 -0000	1.43
@@ -583,28 +583,25 @@
 {
     cairo_surface_t *image;
     cairo_pattern_t *pattern;
-    unsigned char *buffer;
-    unsigned int w, h, stride;
-    read_png_status_t status;
     char *srcdir = getenv ("srcdir");
 
-    status = read_png_argb32 (filename, &buffer, &w,&h, &stride);
-    if (status != READ_PNG_SUCCESS) {
+    image = cairo_image_surface_create_from_png (filename);
+    if (image == NULL) {
 	if (srcdir) {
 	    char *srcdir_filename;
 	    xasprintf (&srcdir_filename, "%s/%s", srcdir, filename);
-	    status = read_png_argb32 (srcdir_filename, &buffer, &w,&h, &stride);
+	    image = cairo_image_surface_create_from_png (srcdir_filename);
 	    free (srcdir_filename);
 	}
+	if (image == NULL)
+	    return NULL;
     }
-    if (status != READ_PNG_SUCCESS)
-	return NULL;
-
-    image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_ARGB32,
-						 w, h, stride);
 
     pattern = cairo_pattern_create_for_surface (image);
+
     cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
 
+    cairo_surface_destroy (image);
+
     return pattern;
 }

Index: trap-clip.c
===================================================================
RCS file: /cvs/cairo/cairo/test/trap-clip.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- trap-clip.c	11 May 2005 03:25:38 -0000	1.4
+++ trap-clip.c	14 Jul 2005 23:18:39 -0000	1.5
@@ -55,6 +55,7 @@
     cairo_pattern_add_color_stop_rgba (pattern, 0, 1, 1, 1, 1);
     cairo_pattern_add_color_stop_rgba (pattern, 1, 0, 0, 0.4, 1);
     cairo_set_source (cr, pattern);
+    cairo_pattern_destroy (pattern);
 }
 
 static void
@@ -64,6 +65,7 @@
 
     pattern = cairo_test_create_png_pattern (cr, png_filename);
     cairo_set_source (cr, pattern);
+    cairo_pattern_destroy (pattern);
 }
 
 static void




More information about the cairo-commit mailing list