From 1676935768b888b3e4038b6dddb4f6362c137345 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Tue, 29 May 2018 17:56:16 +0200 Subject: [PATCH] raster-source: fix when builddir != srcdir When the build dir is different from the source dir, "png.png" is not a valid path. As we can't dispose of an allocated filename, we add an atexit handler. --- test/raster-source.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/raster-source.c b/test/raster-source.c index 5a7646e8a..ee2a570c3 100644 --- a/test/raster-source.c +++ b/test/raster-source.c @@ -34,6 +34,8 @@ #define WIDTH 200 #define HEIGHT 80 +static char *png_filename = NULL; + /* Lazy way of determining PNG dimensions... */ static void png_dimensions (const char *filename, @@ -84,15 +86,26 @@ release (cairo_pattern_t *pattern, void *closure, cairo_surface_t *image) cairo_surface_destroy (image); } +static void +free_filename(void) +{ + free (png_filename); +} + static cairo_test_status_t draw (cairo_t *cr, int width, int height) { - const char *png_filename = "png.png"; cairo_pattern_t *png, *red; cairo_content_t content; int png_width, png_height; int i, j; + if (png_filename == NULL) { + const cairo_test_context_t *ctx = cairo_test_get_context (cr); + xasprintf (&png_filename, "%s/png.png", ctx->srcdir); + atexit (free_filename); + } + png_dimensions (png_filename, &content, &png_width, &png_height); png = cairo_pattern_create_raster_source ((void*)png_filename,