summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2010-05-10 12:45:31 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2010-05-10 12:45:31 +0100
commit8b486db9a9d74b40df296382eb1833bc40ae791a (patch)
treed56187e28380c11b274633cd4849f4f874f19c4f
parent9d863cd3942c3086c24d67305f7a5892604d0eeb (diff)
region: _cairo_region_create_in_error()
Avoid leaks when reporting memfault associated with constructing regions.
-rw-r--r--src/cairo-path-fill.c7
-rw-r--r--src/cairo-region-private.h3
-rw-r--r--src/cairo-region.c63
3 files changed, 60 insertions, 13 deletions
diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c
index f431ea01..24aaa396 100644
--- a/src/cairo-path-fill.c
+++ b/src/cairo-path-fill.c
@@ -220,11 +220,8 @@ _cairo_path_fixed_fill_rectilinear_tessellate_to_region (const cairo_path_fixed_
CLEANUP_TRAPS:
_cairo_traps_fini (&traps);
- if (unlikely (status)) { /* XXX _cairo_region_create_in_error() */
- region = cairo_region_create ();
- if (likely (region->status) == CAIRO_STATUS_SUCCESS)
- region->status = status;
- }
+ if (unlikely (status))
+ region = _cairo_region_create_in_error (status);
return region;
}
diff --git a/src/cairo-region-private.h b/src/cairo-region-private.h
index e29961dc..11070ba7 100644
--- a/src/cairo-region-private.h
+++ b/src/cairo-region-private.h
@@ -53,6 +53,9 @@ struct _cairo_region {
pixman_region32_t rgn;
};
+cairo_private cairo_region_t *
+_cairo_region_create_in_error (cairo_status_t status);
+
cairo_private void
_cairo_region_init (cairo_region_t *region);
diff --git a/src/cairo-region.c b/src/cairo-region.c
index f0b7d443..1df44b84 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -49,6 +49,57 @@ static const cairo_region_t _cairo_region_nil = {
CAIRO_STATUS_NO_MEMORY, /* status */
};
+cairo_region_t *
+_cairo_region_create_in_error (cairo_status_t status)
+{
+ switch (status) {
+ case CAIRO_STATUS_NO_MEMORY:
+ return (cairo_region_t *) &_cairo_region_nil;
+
+ case CAIRO_STATUS_SUCCESS:
+ case CAIRO_STATUS_LAST_STATUS:
+ ASSERT_NOT_REACHED;
+ /* fall-through */
+ case CAIRO_STATUS_SURFACE_TYPE_MISMATCH:
+ case CAIRO_STATUS_INVALID_STATUS:
+ case CAIRO_STATUS_INVALID_CONTENT:
+ case CAIRO_STATUS_INVALID_FORMAT:
+ case CAIRO_STATUS_INVALID_VISUAL:
+ case CAIRO_STATUS_READ_ERROR:
+ case CAIRO_STATUS_WRITE_ERROR:
+ case CAIRO_STATUS_FILE_NOT_FOUND:
+ case CAIRO_STATUS_TEMP_FILE_ERROR:
+ case CAIRO_STATUS_INVALID_STRIDE:
+ case CAIRO_STATUS_INVALID_SIZE:
+ case CAIRO_STATUS_DEVICE_TYPE_MISMATCH:
+ case CAIRO_STATUS_DEVICE_ERROR:
+ case CAIRO_STATUS_INVALID_RESTORE:
+ case CAIRO_STATUS_INVALID_POP_GROUP:
+ case CAIRO_STATUS_NO_CURRENT_POINT:
+ case CAIRO_STATUS_INVALID_MATRIX:
+ case CAIRO_STATUS_NULL_POINTER:
+ case CAIRO_STATUS_INVALID_STRING:
+ case CAIRO_STATUS_INVALID_PATH_DATA:
+ case CAIRO_STATUS_SURFACE_FINISHED:
+ case CAIRO_STATUS_PATTERN_TYPE_MISMATCH:
+ case CAIRO_STATUS_INVALID_DASH:
+ case CAIRO_STATUS_INVALID_DSC_COMMENT:
+ case CAIRO_STATUS_INVALID_INDEX:
+ case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE:
+ case CAIRO_STATUS_FONT_TYPE_MISMATCH:
+ case CAIRO_STATUS_USER_FONT_IMMUTABLE:
+ case CAIRO_STATUS_USER_FONT_ERROR:
+ case CAIRO_STATUS_NEGATIVE_COUNT:
+ case CAIRO_STATUS_INVALID_CLUSTERS:
+ case CAIRO_STATUS_INVALID_SLANT:
+ case CAIRO_STATUS_INVALID_WEIGHT:
+ case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED:
+ default:
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
+ return (cairo_region_t *) &_cairo_region_nil;
+ }
+}
+
/**
* _cairo_region_set_error:
* @region: a region
@@ -155,17 +206,14 @@ cairo_region_create_rectangles (const cairo_rectangle_int_t *rects,
int i;
region = _cairo_malloc (sizeof (cairo_region_t));
- if (unlikely (region == NULL)) {
- _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
- return (cairo_region_t *) &_cairo_region_nil;
- }
+ if (unlikely (region == NULL))
+ return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
if (count > ARRAY_LENGTH (stack_pboxes)) {
pboxes = _cairo_malloc_ab (count, sizeof (pixman_box32_t));
if (unlikely (pboxes == NULL)) {
free (region);
- _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
- return (cairo_region_t *) &_cairo_region_nil;
+ return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
}
}
@@ -183,8 +231,7 @@ cairo_region_create_rectangles (const cairo_rectangle_int_t *rects,
if (unlikely (i == 0)) {
free (region);
- _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
- return (cairo_region_t *) &_cairo_region_nil;
+ return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
}
CAIRO_REFERENCE_COUNT_INIT (&region->ref_count, 1);