[test-paginated] Free resources if fail to create the test surface.

Ensure that all the locally allocated resources are freed if we fail
to allocate the paginated test surface.
This commit is contained in:
Chris Wilson 2007-10-05 00:57:38 +01:00
parent 60ffeecd48
commit d2557cd5ee

View file

@ -69,6 +69,7 @@ _cairo_test_paginated_surface_create_for_data (unsigned char *data,
{
cairo_status_t status;
cairo_surface_t *target;
cairo_surface_t *paginated;
test_paginated_surface_t *surface;
target = _cairo_image_surface_create_for_data_with_content (data, content,
@ -80,6 +81,7 @@ _cairo_test_paginated_surface_create_for_data (unsigned char *data,
surface = malloc (sizeof (test_paginated_surface_t));
if (surface == NULL) {
cairo_surface_destroy (target);
_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return (cairo_surface_t *) &_cairo_surface_nil;
}
@ -89,8 +91,14 @@ _cairo_test_paginated_surface_create_for_data (unsigned char *data,
surface->target = target;
return _cairo_paginated_surface_create (&surface->base, content, width, height,
&test_paginated_surface_paginated_backend);
paginated = _cairo_paginated_surface_create (&surface->base,
content, width, height,
&test_paginated_surface_paginated_backend);
if (paginated->status) {
cairo_surface_destroy (target);
free (surface);
}
return paginated;
}
static cairo_status_t