[pattern] Do not modify outparam on error path.

The pdf backend was crashing as a failed pattern copy stored an invalid
pointer with the resource group.
This commit is contained in:
Chris Wilson 2009-04-01 11:43:16 +01:00
parent 82cccb2672
commit 75b06b8bdb

View file

@ -250,9 +250,10 @@ _cairo_pattern_fini (cairo_pattern_t *pattern)
}
cairo_status_t
_cairo_pattern_create_copy (cairo_pattern_t **pattern,
_cairo_pattern_create_copy (cairo_pattern_t **pattern_out,
const cairo_pattern_t *other)
{
cairo_pattern_t *pattern;
cairo_status_t status;
if (other->status)
@ -260,29 +261,29 @@ _cairo_pattern_create_copy (cairo_pattern_t **pattern,
switch (other->type) {
case CAIRO_PATTERN_TYPE_SOLID:
*pattern = malloc (sizeof (cairo_solid_pattern_t));
pattern = malloc (sizeof (cairo_solid_pattern_t));
break;
case CAIRO_PATTERN_TYPE_SURFACE:
*pattern = malloc (sizeof (cairo_surface_pattern_t));
pattern = malloc (sizeof (cairo_surface_pattern_t));
break;
case CAIRO_PATTERN_TYPE_LINEAR:
*pattern = malloc (sizeof (cairo_linear_pattern_t));
pattern = malloc (sizeof (cairo_linear_pattern_t));
break;
case CAIRO_PATTERN_TYPE_RADIAL:
*pattern = malloc (sizeof (cairo_radial_pattern_t));
pattern = malloc (sizeof (cairo_radial_pattern_t));
break;
}
if (unlikely (*pattern == NULL))
if (unlikely (pattern == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
status = _cairo_pattern_init_copy (*pattern, other);
status = _cairo_pattern_init_copy (pattern, other);
if (unlikely (status)) {
free (*pattern);
free (pattern);
return status;
}
CAIRO_REFERENCE_COUNT_INIT (&(*pattern)->ref_count, 1);
CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 1);
*pattern_out = pattern;
return CAIRO_STATUS_SUCCESS;
}