diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index b6c2c80bc..fcc05b877 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -76,6 +76,7 @@ #include #include #include +#include #if HAVE_UNISTD_H && HAVE_FCNTL_H && HAVE_SIGNAL_H && HAVE_SYS_STAT_H && HAVE_SYS_SOCKET_H && HAVE_SYS_UN_H #include @@ -170,6 +171,9 @@ _cairo_boilerplate_get_image_surface (cairo_surface_t *src, cairo_surface_t *surface; cairo_t *cr; + if (cairo_surface_status (src)) + return cairo_surface_reference (src); + #if 0 if (cairo_surface_get_type (src) == CAIRO_SURFACE_TYPE_IMAGE) { int ww = cairo_image_surface_get_width (src); @@ -973,7 +977,7 @@ cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file) goto FAIL; } if (cairo_surface_status (image)) - goto FAIL; + return image; data = cairo_image_surface_get_data (image); stride = cairo_image_surface_get_stride (image); @@ -1017,8 +1021,14 @@ cairo_boilerplate_convert_to_image (const char *filename, int page) RETRY: file = cairo_boilerplate_open_any2ppm (filename, page, flags); - if (file == NULL) - return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR); + if (file == NULL) { + switch (errno) { + case ENOMEM: + return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + default: + return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR); + } + } image = cairo_boilerplate_image_surface_create_from_ppm_stream (file); ret = pclose (file); diff --git a/test/cairo-test.c b/test/cairo-test.c index 264fed50a..568d8f811 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -910,7 +910,42 @@ REPEAT: cairo_status_t diff_status; if (target->finish_surface != NULL) { +#if HAVE_MEMFAULT + /* We need to re-enable faults as most meta-surface processing + * is done during cairo_surface_finish(). + */ + VALGRIND_CLEAR_FAULTS (); + last_fault_count = VALGRIND_COUNT_FAULTS (); + VALGRIND_ENABLE_FAULTS (); +#endif + diff_status = target->finish_surface (surface); + +#if HAVE_MEMFAULT + VALGRIND_DISABLE_FAULTS (); + + if (ctx->malloc_failure && + VALGRIND_COUNT_FAULTS () - last_fault_count > 0 && + diff_status == CAIRO_STATUS_NO_MEMORY) + { + cairo_destroy (cr); + cairo_surface_destroy (surface); + if (target->cleanup) + target->cleanup (closure); + if (ctx->thread == 0) { + cairo_debug_reset_static_data (); +#if HAVE_FCFINI + FcFini (); +#endif + if (VALGRIND_COUNT_LEAKS () > 0) { + VALGRIND_PRINT_FAULTS (); + VALGRIND_PRINT_LEAKS (); + } + } + + goto REPEAT; + } +#endif if (diff_status) { cairo_test_log (ctx, "Error: Failed to finish surface: %s\n", cairo_status_to_string (diff_status));