[cairo-commit] src/cairo-path-fill.c src/cairo-region.c src/cairo-region-private.h

Chris Wilson ickle at kemper.freedesktop.org
Mon May 10 04:46:33 PDT 2010


 src/cairo-path-fill.c      |    7 +----
 src/cairo-region-private.h |    3 ++
 src/cairo-region.c         |   63 +++++++++++++++++++++++++++++++++++++++------
 3 files changed, 60 insertions(+), 13 deletions(-)

New commits:
commit 8b486db9a9d74b40df296382eb1833bc40ae791a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon May 10 12:45:31 2010 +0100

    region: _cairo_region_create_in_error()
    
    Avoid leaks when reporting memfault associated with constructing
    regions.

diff --git a/src/cairo-path-fill.c b/src/cairo-path-fill.c
index f431ea0..24aaa39 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 e29961d..11070ba 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 f0b7d44..1df44b8 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);


More information about the cairo-commit mailing list