Merge branch 'fix_memory_allocation' into 'master'

Added checks for failed strdups in cairo-recording-surface.c

See merge request cairo/cairo!99
This commit is contained in:
Uli Schlachter 2021-01-04 15:47:29 +00:00
commit cb3618f76d

View file

@ -1125,9 +1125,18 @@ _cairo_recording_surface_tag (void *abstract_surface,
command->begin = begin;
command->tag_name = strdup (tag_name);
if (unlikely (command->tag_name == NULL)) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto CLEANUP_COMMAND;
}
if (begin) {
if (attributes)
if (attributes) {
command->attributes = strdup (attributes);
if (unlikely (command->attributes == NULL)) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto CLEANUP_STRINGS;
}
}
status = _cairo_pattern_init_snapshot (&command->source.base, source);
if (unlikely (status))
@ -1144,9 +1153,9 @@ _cairo_recording_surface_tag (void *abstract_surface,
status = _cairo_recording_surface_commit (surface, &command->header);
if (unlikely (status)) {
if (begin)
goto CLEANUP_STRINGS;
else
goto CLEANUP_STYLE;
else
goto CLEANUP_STRINGS;
}
_cairo_recording_surface_destroy_bbtree (surface);
@ -1451,9 +1460,18 @@ _cairo_recording_surface_copy__tag (cairo_recording_surface_t *surface,
command->begin = src->tag.begin;
command->tag_name = strdup (src->tag.tag_name);
if (unlikely (command->tag_name == NULL)) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto err_command;
}
if (src->tag.begin) {
if (src->tag.attributes)
if (src->tag.attributes) {
command->attributes = strdup (src->tag.attributes);
if (unlikely (command->attributes == NULL)) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto err_command;
}
}
status = _cairo_pattern_init_copy (&command->source.base,
&src->tag.source.base);
@ -1472,9 +1490,9 @@ _cairo_recording_surface_copy__tag (cairo_recording_surface_t *surface,
status = _cairo_recording_surface_commit (surface, &command->header);
if (unlikely (status)) {
if (src->tag.begin)
goto err_command;
else
goto err_style;
else
goto err_command;
}
return CAIRO_STATUS_SUCCESS;