From 40edca337e3976ddca98caafcbab950000e66880 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 14 Jul 2005 16:18:39 +0000 Subject: [PATCH] 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. Add calls to cairo_pattern_destroy to close two memory leaks. --- ChangeLog | 10 ++++++++++ test/cairo-test.c | 19 ++++++++----------- test/trap-clip.c | 2 ++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 85ee99009..e84a78c6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-07-14 Carl Worth + + * 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. + 2005-07-14 Carl Worth * src/cairo-pattern.c: (_cairo_pattern_acquire_surfaces): Fix up diff --git a/test/cairo-test.c b/test/cairo-test.c index 49294512a..4274bef4b 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -583,28 +583,25 @@ cairo_test_create_png_pattern (cairo_t *cr, const char *filename) { 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; } diff --git a/test/trap-clip.c b/test/trap-clip.c index 2ad43ea5f..dddb94cb2 100644 --- a/test/trap-clip.c +++ b/test/trap-clip.c @@ -55,6 +55,7 @@ set_gradient_pattern (cairo_t *cr, int x, int y) 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 @@ set_image_pattern (cairo_t *cr, int x, int y) pattern = cairo_test_create_png_pattern (cr, png_filename); cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); } static void