diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-01-29 09:50:38 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-01-29 10:10:41 +0000 |
commit | 8388af137841679b7c510980daf3cec1427b6e6b (patch) | |
tree | 2abd6336f5c3944b0d346c64f2fdaa2c6a78cb68 | |
parent | 3752f690b467432ab5b1058d450cb79d719a794a (diff) |
[test] Trivial fixes for error paths.
Kill a few leaks along error paths in the test code.
-rw-r--r-- | test/create-from-png-stream.c | 36 | ||||
-rw-r--r-- | test/mime-data.c | 4 |
2 files changed, 32 insertions, 8 deletions
diff --git a/test/create-from-png-stream.c b/test/create-from-png-stream.c index 3d1957db..a5c53952 100644 --- a/test/create-from-png-stream.c +++ b/test/create-from-png-stream.c @@ -27,6 +27,7 @@ #include <stdlib.h> #include <stdio.h> +#include <errno.h> #define WIDTH 2 #define HEIGHT 2 @@ -51,15 +52,24 @@ draw (cairo_t *cr, int width, int height) char *filename; FILE *file; cairo_surface_t *surface; + cairo_status_t status; xasprintf (&filename, "%s/%s", ctx->srcdir, "create-from-png-stream.ref.png"); file = fopen (filename, "rb"); if (file == NULL) { - cairo_test_log (ctx, "Error: failed to open file: %s\n", filename); + cairo_test_status_t ret; + + ret = CAIRO_TEST_FAILURE; + if (errno == ENOMEM) + ret = cairo_test_status_from_status (ctx, CAIRO_STATUS_NO_MEMORY); + + if (ret != CAIRO_TEST_NO_MEMORY) + cairo_test_log (ctx, "Error: failed to open file: %s\n", filename); + free (filename); - return CAIRO_TEST_FAILURE; + return ret; } surface = cairo_image_surface_create_from_png_stream (read_png_from_file, @@ -67,13 +77,23 @@ draw (cairo_t *cr, int width, int height) fclose (file); - if (cairo_surface_status (surface)) { - cairo_test_log (ctx, - "Error: failed to create surface from PNG: %s - %s\n", - filename, - cairo_status_to_string (cairo_surface_status (surface))); + status = cairo_surface_status (surface); + if (status) { + cairo_test_status_t ret; + + cairo_surface_destroy (surface); + + ret = cairo_test_status_from_status (ctx, status); + if (ret != CAIRO_TEST_NO_MEMORY) { + cairo_test_log (ctx, + "Error: failed to create surface from PNG: %s - %s\n", + filename, + cairo_status_to_string (status)); + } + free (filename); - return CAIRO_TEST_FAILURE; + + return ret; } free (filename); diff --git a/test/mime-data.c b/test/mime-data.c index febc3226..b1074cde 100644 --- a/test/mime-data.c +++ b/test/mime-data.c @@ -44,6 +44,9 @@ read_file (const cairo_test_context_t *ctx, if (file == NULL) { char path[4096]; + if (errno == ENOMEM) + return CAIRO_STATUS_NO_MEMORY; + /* try again with srcdir */ snprintf (path, sizeof (path), "%s/%s", ctx->srcdir, filename); @@ -100,6 +103,7 @@ paint_file (cairo_t *cr, free, mime_data); if (status) { cairo_surface_destroy (image); + free (mime_data); return cairo_test_status_from_status (ctx, status); } |