[cairo-commit] 6 commits - src/cairo-array.c src/cairo-atsui-font.c src/cairo-base85-stream.c src/cairo-bentley-ottmann.c src/cairo.c src/cairo-cache.c src/cairo-cff-subset.c src/cairo-clip.c src/cairo-deflate-stream.c src/cairo-directfb-surface.c src/cairo-font-face.c src/cairo-font-options.c src/cairo-ft-font.c src/cairo-glitz-surface.c src/cairo-gstate.c src/cairo-hash.c src/cairo-hull.c src/cairo-image-surface.c src/cairo-lzw.c src/cairo-malloc-private.h src/cairo-meta-surface.c src/cairo-output-stream.c src/cairo-paginated-surface.c src/cairo-path-fixed.c src/cairo-path-stroke.c src/cairo-pattern.c src/cairo-pdf-surface.c src/cairo-pen.c src/cairo-polygon.c src/cairo-ps-surface.c src/cairo-quartz-surface.c src/cairo-region.c src/cairo-scaled-font.c src/cairo-scaled-font-subsets.c src/cairo-skiplist.c src/cairo-spline.c src/cairo-stroke-style.c src/cairo-surface.c src/cairo-surface-fallback.c src/cairo-traps.c src/cairo-truetype-subset.c src/cairo-type1-fallback.c src/cairo-type1-subset.c src/cairo-unicode.c src/cairo-win32-font.c src/cairo-win32-surface.c src/cairo-xcb-surface.c src/cairo-xlib-display.c src/cairo-xlib-surface.c src/test-meta-surface.c test/copy-path.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Oct 4 01:21:27 PDT 2007


 src/cairo-array.c               |   10 +++--
 src/cairo-atsui-font.c          |    1 
 src/cairo-base85-stream.c       |    4 +-
 src/cairo-bentley-ottmann.c     |   12 +++++-
 src/cairo-cache.c               |    4 +-
 src/cairo-cff-subset.c          |   72 ++++++++++++++++++++++++++++++----------
 src/cairo-clip.c                |    4 +-
 src/cairo-deflate-stream.c      |    4 +-
 src/cairo-directfb-surface.c    |   32 ++++++++++++-----
 src/cairo-font-face.c           |    4 +-
 src/cairo-font-options.c        |   11 ++++--
 src/cairo-ft-font.c             |   17 ++++++---
 src/cairo-glitz-surface.c       |   35 +++++++++++++++----
 src/cairo-gstate.c              |   13 +++++--
 src/cairo-hash.c                |    9 +++--
 src/cairo-hull.c                |    4 +-
 src/cairo-image-surface.c       |   12 +++++-
 src/cairo-lzw.c                 |    8 +++-
 src/cairo-malloc-private.h      |   30 ++++++++++++++--
 src/cairo-meta-surface.c        |   26 +++++++++++---
 src/cairo-output-stream.c       |   21 ++++++++---
 src/cairo-paginated-surface.c   |    4 +-
 src/cairo-path-fixed.c          |    8 +++-
 src/cairo-path-stroke.c         |    8 +++-
 src/cairo-pattern.c             |    9 +++--
 src/cairo-pdf-surface.c         |   10 ++++-
 src/cairo-pen.c                 |   15 ++++++--
 src/cairo-polygon.c             |    4 +-
 src/cairo-ps-surface.c          |   19 +++++++---
 src/cairo-quartz-surface.c      |   14 +++++++
 src/cairo-region.c              |    4 +-
 src/cairo-scaled-font-subsets.c |   18 +++++++---
 src/cairo-scaled-font.c         |    3 +
 src/cairo-skiplist.c            |    5 ++
 src/cairo-spline.c              |    4 +-
 src/cairo-stroke-style.c        |    4 +-
 src/cairo-surface-fallback.c    |    2 +
 src/cairo-surface.c             |    1 
 src/cairo-traps.c               |    8 +++-
 src/cairo-truetype-subset.c     |   13 ++++++-
 src/cairo-type1-fallback.c      |    7 +++
 src/cairo-type1-subset.c        |   26 +++++++++++---
 src/cairo-unicode.c             |    8 +++-
 src/cairo-win32-font.c          |    9 +++--
 src/cairo-win32-surface.c       |    5 ++
 src/cairo-xcb-surface.c         |   23 ++++++++++--
 src/cairo-xlib-display.c        |    4 +-
 src/cairo-xlib-surface.c        |   19 ++++++++--
 src/cairo.c                     |   12 +++++-
 src/test-meta-surface.c         |    4 +-
 test/copy-path.c                |   15 ++++++++
 51 files changed, 482 insertions(+), 136 deletions(-)

New commits:
diff-tree ef5f460eb1f86a73e016c1150723ae1e70b3b037 (from 8ad56b308ae8bbecfe9873c21551a6d4b2302420)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Oct 4 09:08:46 2007 +0100

    [cairo-path] Check for an empty path in cairo_append_path().
    
    As we now generate empty paths, we must be able to handle empty paths
    in the user facing API. cairo_append_path() has an explicit check, and
    raises an error, for a NULL path->data, so we need to check the
    path->num_data first for empty paths.

diff --git a/src/cairo.c b/src/cairo.c
index 4e3bfda..4a1c73b 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -3415,6 +3415,9 @@ cairo_append_path (cairo_t		*cr,
 	return;
     }
 
+    if (path->num_data == 0)
+	return;
+
     if (path->data == NULL) {
 	_cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
 	return;
diff --git a/test/copy-path.c b/test/copy-path.c
index 256f461..362bb34 100644
--- a/test/copy-path.c
+++ b/test/copy-path.c
@@ -141,7 +141,13 @@ draw (cairo_t *cr, int width, int height
 	cairo_path_destroy (path);
 	return CAIRO_TEST_FAILURE;
     }
+    cairo_append_path (cr, path);
     cairo_path_destroy (path);
+    if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
+	cairo_test_log ("Error: cairo_append_path failed with a copy of an empty path, returned status of %s\n",
+			cairo_status_to_string (cairo_status (cr)));
+	return CAIRO_TEST_FAILURE;
+    }
 
     /* We draw in the default black, so paint white first. */
     cairo_save (cr);
@@ -224,6 +230,15 @@ main (void)
     path.num_data = 0;
     path.status = CAIRO_STATUS_SUCCESS;
     cairo_append_path (cr, &path);
+    if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
+	return 1;
+    cairo_destroy (cr);
+
+    cr = cairo_create (surface);
+    path.data = NULL;
+    path.num_data = 1;
+    path.status = CAIRO_STATUS_SUCCESS;
+    cairo_append_path (cr, &path);
     if (cairo_status (cr) != CAIRO_STATUS_NULL_POINTER)
 	return 1;
     cairo_destroy (cr);
diff-tree 8ad56b308ae8bbecfe9873c21551a6d4b2302420 (from 66664596559c55913fb0b9c8784fe8ab862c217b)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Oct 4 00:38:12 2007 +0100

    [malloc/error] Add call to _cairo_error() after a failed malloc.
    
    Blitz all allocations to ensure that they raise a
    _cairo_error(CAIRO_STATUS_NO_MEMORY) on failure.

diff --git a/src/cairo-array.c b/src/cairo-array.c
index 3525c78..58c699e 100644
--- a/src/cairo-array.c
+++ b/src/cairo-array.c
@@ -132,8 +132,11 @@ _cairo_array_grow_by (cairo_array_t *arr
 
     if (array->elements == NULL) {
 	array->elements = malloc (sizeof (char *));
-	if (array->elements == NULL)
+	if (array->elements == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
+
 	*array->elements = NULL;
     }
 
@@ -143,6 +146,7 @@ _cairo_array_grow_by (cairo_array_t *arr
 
     if (new_elements == NULL) {
 	array->size = old_size;
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 1e174ec..ab567c6 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -811,6 +811,7 @@ _cairo_atsui_font_text_to_glyphs (void		
     *glyphs =
 	(cairo_glyph_t *) _cairo_malloc_ab(*num_glyphs, sizeof (cairo_glyph_t));
     if (*glyphs == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
diff --git a/src/cairo-base85-stream.c b/src/cairo-base85-stream.c
index 08ae8a7..bfde0cf 100644
--- a/src/cairo-base85-stream.c
+++ b/src/cairo-base85-stream.c
@@ -114,8 +114,10 @@ _cairo_base85_stream_create (cairo_outpu
     cairo_base85_stream_t *stream;
 
     stream = malloc (sizeof (cairo_base85_stream_t));
-    if (stream == NULL)
+    if (stream == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
+    }
 
     _cairo_output_stream_init (&stream->base,
 			       _cairo_base85_stream_write,
diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index 267459c..679b532 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -755,8 +755,10 @@ _cairo_bo_event_queue_init (cairo_bo_eve
      * event type a union so it doesn't always contain the skip
      * elt? */
     events = _cairo_malloc_ab (num_events, sizeof (cairo_bo_event_t) + sizeof(cairo_bo_event_t*));
-    if (events == NULL)
+    if (events == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     sorted_event_ptrs = (cairo_bo_event_t **) (events + num_events);
     event_queue->startstop_events = events;
@@ -1146,8 +1148,10 @@ _cairo_bo_edge_start_or_continue_trap (c
 
     if (edge->next) {
 	trap = edge->deferred_trap = _cairo_freelist_alloc (&bo_traps->freelist);
-	if (!edge->deferred_trap)
+	if (!edge->deferred_trap) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
 
 	trap->right = edge->next;
 	trap->top = top;
@@ -1437,8 +1441,10 @@ _cairo_bentley_ottmann_tessellate_polygo
 	edges = stack_edges;
     } else {
 	edges = _cairo_malloc_ab (polygon->num_edges, sizeof (cairo_bo_edge_t));
-	if (edges == NULL)
+	if (edges == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     /* Figure out the bounding box of the input coordinates and
diff --git a/src/cairo-cache.c b/src/cairo-cache.c
index 18c3d8c..a7c27c1 100644
--- a/src/cairo-cache.c
+++ b/src/cairo-cache.c
@@ -131,8 +131,10 @@ _cairo_cache_create (cairo_cache_keys_eq
     cairo_cache_t *cache;
 
     cache = malloc (sizeof (cairo_cache_t));
-    if (cache == NULL)
+    if (cache == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
 
     status = _cairo_cache_init (cache, keys_equal, entry_destroy, max_size);
     if (status) {
diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 390b149..aac1378 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -389,8 +389,11 @@ cff_index_append_copy (cairo_array_t *in
     element.length = length;
     element.is_copy = TRUE;
     element.data = malloc (element.length);
-    if (element.data == NULL)
-        return CAIRO_STATUS_NO_MEMORY;
+    if (element.data == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return CAIRO_STATUS_NO_MEMORY;
+    }
+
     memcpy (element.data, object, element.length);
 
     return _cairo_array_append (index, &element);
@@ -440,12 +443,16 @@ cff_dict_create_operator (int           
     cff_dict_operator_t *op;
 
     op = malloc (sizeof (cff_dict_operator_t));
-    if (op == NULL)
+    if (op == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return NULL;
+    }
+
     _cairo_dict_init_key (op, operator);
     op->operand = malloc (operand_length);
     if (op->operand == NULL) {
         free (op);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return NULL;
     }
     memcpy (op->operand, operand, operand_length);
@@ -544,16 +551,22 @@ cff_dict_set_operands (cairo_hash_table_
     {
         free (op->operand);
         op->operand = malloc (size);
-        if (op->operand == NULL)
-            return CAIRO_STATUS_NO_MEMORY;
+	if (op->operand == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return CAIRO_STATUS_NO_MEMORY;
+	}
+
         memcpy (op->operand, operand, size);
         op->operand_length = size;
     }
     else
     {
         op = cff_dict_create_operator (operator, operand, size);
-        if (op == NULL)
+        if (op == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
+
 	status = _cairo_hash_table_insert (dict, &op->base);
 	if (status)
 	    return status;
@@ -718,8 +731,10 @@ cairo_cff_font_read_fdselect (cairo_cff_
     int type, num_ranges, first, last, fd, i, j;
 
     font->fdselect = calloc (font->num_glyphs, sizeof (int));
-    if (font->fdselect == NULL)
-        return CAIRO_STATUS_NO_MEMORY;
+    if (font->fdselect == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     type = *p++;
     if (type == 0)
@@ -828,6 +843,7 @@ cairo_cff_font_read_cid_fontdict (cairo_
 fail:
     cff_index_fini (&index);
 
+    _cairo_error (status);
     return status;
 }
 
@@ -1062,20 +1078,28 @@ cairo_cff_font_subset_fontdict (cairo_cf
 
     font->fdselect_subset = calloc (font->scaled_font_subset->num_glyphs,
                                      sizeof (int));
-    if (font->fdselect_subset == NULL)
+    if (font->fdselect_subset == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font->fd_subset_map = calloc (font->num_fontdicts, sizeof (int));
-    if (font->fd_subset_map == NULL)
+    if (font->fd_subset_map == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font->private_dict_offset = calloc (font->num_fontdicts, sizeof (int));
-    if (font->private_dict_offset == NULL)
+    if (font->private_dict_offset == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     reverse_map = calloc (font->num_fontdicts, sizeof (int));
-    if (reverse_map == NULL)
+    if (reverse_map == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     for (i = 0; i < font->num_fontdicts; i++)
         reverse_map[i] = -1;
@@ -1103,18 +1127,24 @@ cairo_cff_font_create_cid_fontdict (cair
 
     font->num_fontdicts = 1;
     font->fd_dict = malloc (sizeof (cairo_hash_table_t *));
-    if (font->fd_dict == NULL)
+    if (font->fd_dict == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     cff_dict_init (&font->fd_dict[0]);
 
     font->fd_subset_map = malloc (sizeof (int));
-    if (font->fd_subset_map == NULL)
+    if (font->fd_subset_map == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font->private_dict_offset = malloc (sizeof (int));
-    if (font->private_dict_offset == NULL)
+    if (font->private_dict_offset == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font->fd_subset_map[0] = 0;
     font->num_subset_fontdicts = 1;
@@ -1668,8 +1698,11 @@ _cairo_cff_font_create (cairo_scaled_fon
         return status;
 
     name = malloc (size);
-    if (name == NULL)
+    if (name == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
+
     status = backend->load_truetype_table (scaled_font_subset->scaled_font,
                                            TT_TAG_name, 0,
                                            (unsigned char *) name, &size);
@@ -1798,6 +1831,7 @@ fail2:
     free (font);
 fail1:
     free (name);
+    _cairo_error (status);
     return status;
 }
 
@@ -1912,6 +1946,7 @@ _cairo_cff_subset_init (cairo_cff_subset
  fail1:
     cairo_cff_font_destroy (font);
 
+    _cairo_error (status);
     return status;
 }
 
@@ -1932,8 +1967,10 @@ _cairo_cff_font_fallback_create (cairo_s
     cairo_cff_font_t *font;
 
     font = malloc (sizeof (cairo_cff_font_t));
-    if (font == NULL)
+    if (font == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font->backend = NULL;
     font->scaled_font_subset = scaled_font_subset;
@@ -2000,6 +2037,7 @@ fail2:
     _cairo_array_fini (&font->output);
 fail1:
     free (font);
+    _cairo_error (status);
     return status;
 }
 
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index c1667d2..4f42414 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -276,8 +276,10 @@ _cairo_clip_intersect_path (cairo_clip_t
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     clip_path = malloc (sizeof (cairo_clip_path_t));
-    if (clip_path == NULL)
+    if (clip_path == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     status = _cairo_path_fixed_init_copy (&clip_path->path, path);
     if (status) {
diff --git a/src/cairo-deflate-stream.c b/src/cairo-deflate-stream.c
index 38ce639..618c6be 100644
--- a/src/cairo-deflate-stream.c
+++ b/src/cairo-deflate-stream.c
@@ -118,8 +118,10 @@ _cairo_deflate_stream_create (cairo_outp
     cairo_deflate_stream_t *stream;
 
     stream = malloc (sizeof (cairo_deflate_stream_t));
-    if (stream == NULL)
+    if (stream == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
+    }
 
     _cairo_output_stream_init (&stream->base,
 			       _cairo_deflate_stream_write,
diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index 409f79d..50f926c 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -414,8 +414,10 @@ _cairo_directfb_surface_create_similar (
 
     format = _cairo_format_from_content (content);             
     surface = calloc (1, sizeof(cairo_directfb_surface_t));
-    if (!surface) 
+    if (!surface) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return NULL;
+    }
    
     surface->dfbsurface = _directfb_buffer_surface_create (source->dfb,
                                               cairo_to_directfb_format (format),
@@ -1119,6 +1121,7 @@ _cairo_directfb_surface_set_clip_region 
             if (!surface->clips) {
                 _cairo_region_boxes_fini (region, boxes);
                 surface->n_clips = 0;
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
                 return CAIRO_STATUS_NO_MEMORY;
             }
         
@@ -1211,12 +1214,15 @@ _directfb_allocate_font_cache (IDirectFB
     cairo_directfb_font_cache_t *cache;
 
     cache = calloc (1, sizeof(cairo_directfb_font_cache_t));
-    if (!cache)
-        return NULL;
+    if (!cache) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return NULL;
+    }
 
     cache->dfbsurface = _directfb_buffer_surface_create( dfb, DSPF_A8, width, height);
     if (!cache->dfbsurface) {
         free (cache);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return NULL;
     }
 
@@ -1313,8 +1319,10 @@ _directfb_acquire_font_cache (cairo_dire
             
             /* Remember glyph location */ 
             rect = malloc (sizeof(DFBRectangle));
-            if (!rect)
+            if (!rect) {
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
                 return CAIRO_STATUS_NO_MEMORY;
+	    }
             *rect = rects[n];
             
             scaled_glyph->surface_private = rect;
@@ -1351,8 +1359,10 @@ _directfb_acquire_font_cache (cairo_dire
                         "Reallocating font cache (%dx%d).\n", w, h);
             
             new_cache = _directfb_allocate_font_cache (surface->dfb, w, h);
-            if (!new_cache)
+            if (!new_cache) {
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
                 return CAIRO_STATUS_NO_MEMORY;
+	    }
             
             new_cache->dfbsurface->Blit (new_cache->dfbsurface,
                                      cache->dfbsurface, NULL, 0, 0);
@@ -1366,8 +1376,10 @@ _directfb_acquire_font_cache (cairo_dire
                     "Allocating font cache (%dx%d).\n", w, h);
         
         cache = _directfb_allocate_font_cache (surface->dfb, w, h);
-        if (!cache)
-            return CAIRO_STATUS_NO_MEMORY;
+	if (!cache) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return CAIRO_STATUS_NO_MEMORY;
+	}
             
         scaled_font->surface_backend = &cairo_directfb_surface_backend;
         scaled_font->surface_private = cache;
@@ -1629,8 +1641,10 @@ cairo_directfb_surface_create (IDirectFB
     cairo_directfb_surface_backend_init (dfb);
         
     surface = calloc (1, sizeof(cairo_directfb_surface_t));
-    if (!surface)
-        return NULL;
+    if (!surface) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return NULL;
+    }
         
     dfbsurface->GetPixelFormat (dfbsurface, &format);
     _cairo_surface_init (&surface->base, &cairo_directfb_surface_backend,
diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c
index c648020..b3bcc84 100644
--- a/src/cairo-font-face.c
+++ b/src/cairo-font-face.c
@@ -395,8 +395,10 @@ _cairo_toy_font_face_create (const char 
 
     /* Otherwise create it and insert into hash table. */
     font_face = malloc (sizeof (cairo_toy_font_face_t));
-    if (font_face == NULL)
+    if (font_face == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto UNWIND_HASH_TABLE_LOCK;
+    }
 
     status = _cairo_toy_font_face_init (font_face, family, slant, weight);
     if (status)
diff --git a/src/cairo-font-options.c b/src/cairo-font-options.c
index 33b021d..b3a5660 100644
--- a/src/cairo-font-options.c
+++ b/src/cairo-font-options.c
@@ -86,10 +86,13 @@ _cairo_font_options_init_copy (cairo_fon
 cairo_font_options_t *
 cairo_font_options_create (void)
 {
-    cairo_font_options_t *options = malloc (sizeof (cairo_font_options_t));
+    cairo_font_options_t *options;
 
-    if (!options)
+    options = malloc (sizeof (cairo_font_options_t));
+    if (!options) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_font_options_t *)&_cairo_font_options_nil;
+    }
 
     _cairo_font_options_init_default (options);
 
@@ -119,8 +122,10 @@ cairo_font_options_copy (const cairo_fon
 	return (cairo_font_options_t *)&_cairo_font_options_nil;
 
     options = malloc (sizeof (cairo_font_options_t));
-    if (!options)
+    if (!options) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_font_options_t *)&_cairo_font_options_nil;
+    }
 
     _cairo_font_options_init_copy (options, original);
 
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 38a4a8d..753810a 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -176,8 +176,10 @@ _cairo_ft_unscaled_font_map_create (void
     assert (cairo_ft_unscaled_font_map == NULL);
 
     font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t));
-    if (font_map == NULL)
+    if (font_map == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
+    }
 
     font_map->hash_table =
 	_cairo_hash_table_create (_cairo_ft_unscaled_font_keys_equal);
@@ -423,8 +425,10 @@ _cairo_ft_unscaled_font_create_for_patte
 
     /* Otherwise create it and insert into hash table. */
     unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
-    if (unscaled == NULL)
+    if (unscaled == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto UNWIND_FONT_MAP_LOCK;
+    }
 
     status = _cairo_ft_unscaled_font_init (unscaled, filename, id, NULL);
     if (status)
@@ -456,8 +460,10 @@ _cairo_ft_unscaled_font_create_from_face
     cairo_ft_unscaled_font_t *unscaled;
 
     unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
-    if (unscaled == NULL)
+    if (unscaled == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
 
     status = _cairo_ft_unscaled_font_init (unscaled, NULL, 0, face);
     if (status) {
@@ -1042,7 +1048,6 @@ _render_glyph_outline (FT_Face          
 	bitmap.width = width * hmul;
 	bitmap.rows = height * vmul;
 	bitmap.buffer = calloc (stride, bitmap.rows);
-
 	if (bitmap.buffer == NULL) {
 	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c
index 4b0e74b..5e68fc7 100644
--- a/src/cairo-glitz-surface.c
+++ b/src/cairo-glitz-surface.c
@@ -165,8 +165,10 @@ _cairo_glitz_get_boxes_from_region (cair
         return NULL;
 
     gboxes = _cairo_malloc_ab (n, sizeof(glitz_box_t));
-    if (gboxes == NULL)
+    if (gboxes == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
         goto done;
+    }
 
     for (i = 0; i < n; i++) {
         gboxes[i].x1 = cboxes[i].p1.x;
@@ -269,12 +271,15 @@ _cairo_glitz_surface_get_image (cairo_gl
     pf.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
 
     pixels = _cairo_malloc_ab (height, pf.bytes_per_line);
-    if (!pixels)
+    if (!pixels) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     buffer = glitz_buffer_create_for_data (pixels);
     if (!buffer) {
 	free (pixels);
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
@@ -775,8 +780,10 @@ _cairo_glitz_pattern_acquire_surface (ca
             data = malloc (size1 + size2);
         }
 
-	if (!data)
+	if (!data) {
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
 
 	params = (glitz_fixed16_16_t *) data;
 	pixels = (unsigned int *)
@@ -786,6 +793,7 @@ _cairo_glitz_pattern_acquire_surface (ca
 	if (!buffer)
 	{
 	    free (data);
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    return CAIRO_STATUS_NO_MEMORY;
 	}
 
@@ -1304,6 +1312,7 @@ _cairo_glitz_surface_composite_trapezoid
 							  &attributes);
 		    if (src_pattern == &tmp_src_pattern.base)
 			_cairo_pattern_fini (&tmp_src_pattern.base);
+		    _cairo_error (CAIRO_STATUS_SUCCESS);
 		    return CAIRO_STATUS_NO_MEMORY;
 		}
 
@@ -1317,6 +1326,7 @@ _cairo_glitz_surface_composite_trapezoid
 							  &attributes);
 		    if (src_pattern == &tmp_src_pattern.base)
 			_cairo_pattern_fini (&tmp_src_pattern.base);
+		    _cairo_error (CAIRO_STATUS_SUCCESS);
 		    return CAIRO_STATUS_NO_MEMORY;
 		}
 	    }
@@ -1353,6 +1363,7 @@ _cairo_glitz_surface_composite_trapezoid
 	    _cairo_glitz_pattern_release_surface (src_pattern, src, &attributes);
 	    if (src_pattern == &tmp_src_pattern.base)
 		_cairo_pattern_fini (&tmp_src_pattern.base);
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    return CAIRO_STATUS_NO_MEMORY;
 	}
 
@@ -1565,8 +1576,10 @@ _cairo_glitz_area_create (cairo_glitz_ro
     int		       n = 4;
 
     area = malloc (sizeof (cairo_glitz_area_t));
-    if (!area)
+    if (!area) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return NULL;
+    }
 
     area->level   = level;
     area->x	  = x;
@@ -1900,8 +1913,10 @@ _cairo_glitz_surface_font_init (cairo_gl
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     font_private = malloc (sizeof (cairo_glitz_surface_font_private_t));
-    if (!font_private)
+    if (!font_private) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font_private->surface = glitz_surface_create (drawable, surface_format,
 						  GLYPH_CACHE_TEXTURE_SIZE,
@@ -1986,8 +2001,10 @@ _cairo_glitz_surface_add_glyph (cairo_gl
     if (glyph_private == NULL)
     {
 	glyph_private = malloc (sizeof (cairo_glitz_surface_glyph_private_t));
-	if (!glyph_private)
+	if (!glyph_private) {
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
 
 	glyph_private->area   = NULL;
 	glyph_private->locked = FALSE;
@@ -2151,8 +2168,10 @@ _cairo_glitz_surface_old_show_glyphs (ca
             goto FAIL1;
 
 	data = malloc (size1 + size2);
-	if (!data)
+	if (!data) {
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    goto FAIL1;
+	}
 
 	scaled_glyphs = (cairo_scaled_glyph_t **) data;
 	vertices = (glitz_float_t *) (data + num_glyphs * sizeof (void *));
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 232b040..32d02e5 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -207,8 +207,10 @@ _cairo_gstate_clone (cairo_gstate_t *oth
     assert (other != NULL);
 
     gstate = malloc (sizeof (cairo_gstate_t));
-    if (gstate == NULL)
+    if (gstate == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return NULL;
+    }
 
     status = _cairo_gstate_init_copy (gstate, other);
     if (status) {
@@ -533,6 +535,7 @@ _cairo_gstate_set_dash (cairo_gstate_t *
     gstate->stroke_style.dash = _cairo_malloc_ab (gstate->stroke_style.num_dashes, sizeof (double));
     if (gstate->stroke_style.dash == NULL) {
 	gstate->stroke_style.num_dashes = 0;
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
@@ -1573,8 +1576,10 @@ _cairo_gstate_show_glyphs (cairo_gstate_
 	transformed_glyphs = stack_transformed_glyphs;
     } else {
 	transformed_glyphs = _cairo_malloc_ab (num_glyphs, sizeof(cairo_glyph_t));
-	if (transformed_glyphs == NULL)
+	if (transformed_glyphs == NULL) {
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     _cairo_gstate_transform_glyphs_to_backend (gstate, glyphs, num_glyphs,
@@ -1618,8 +1623,10 @@ _cairo_gstate_glyph_path (cairo_gstate_t
       transformed_glyphs = stack_transformed_glyphs;
     else
       transformed_glyphs = _cairo_malloc_ab (num_glyphs, sizeof(cairo_glyph_t));
-    if (transformed_glyphs == NULL)
+    if (transformed_glyphs == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     _cairo_gstate_transform_glyphs_to_backend (gstate, glyphs, num_glyphs,
                                                transformed_glyphs);
diff --git a/src/cairo-hash.c b/src/cairo-hash.c
index 9934375..09450f7 100644
--- a/src/cairo-hash.c
+++ b/src/cairo-hash.c
@@ -149,8 +149,10 @@ _cairo_hash_table_create (cairo_hash_key
     cairo_hash_table_t *hash_table;
 
     hash_table = malloc (sizeof (cairo_hash_table_t));
-    if (hash_table == NULL)
+    if (hash_table == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return NULL;
+    }
 
     hash_table->keys_equal = keys_equal;
 
@@ -160,6 +162,7 @@ _cairo_hash_table_create (cairo_hash_key
 				  sizeof(cairo_hash_entry_t *));
     if (hash_table->entries == NULL) {
 	free (hash_table);
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return NULL;
     }
 
@@ -328,8 +331,10 @@ _cairo_hash_table_resize  (cairo_hash_ta
 
     new_size = tmp.arrangement->size;
     tmp.entries = calloc (new_size, sizeof (cairo_hash_entry_t*));
-    if (tmp.entries == NULL)
+    if (tmp.entries == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     for (i = 0; i < hash_table->arrangement->size; ++i) {
 	if (ENTRY_IS_LIVE (hash_table->entries[i])) {
diff --git a/src/cairo-hull.c b/src/cairo-hull.c
index c56e9e0..fb4e71c 100644
--- a/src/cairo-hull.c
+++ b/src/cairo-hull.c
@@ -63,8 +63,10 @@ _cairo_hull_create (cairo_pen_vertex_t *
     vertices[0].point = tmp;
 
     hull = _cairo_malloc_ab (num_vertices, sizeof (cairo_hull_t));
-    if (hull == NULL)
+    if (hull == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return NULL;
+    }
 
     for (i = 0; i < num_vertices; i++) {
 	hull[i].point = vertices[i].point;
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 9fbdb59..1b80173 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1062,8 +1062,10 @@ _cairo_image_surface_fill_rectangles (vo
 
     if (num_rects > ARRAY_LENGTH(stack_rects)) {
 	pixman_rects = _cairo_malloc_ab (num_rects, sizeof(pixman_rectangle16_t));
-	if (pixman_rects == NULL)
+	if (pixman_rects == NULL) {
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }		 
 
     for (i = 0; i < num_rects; i++) {
@@ -1124,8 +1126,10 @@ _cairo_image_surface_composite_trapezoid
     /* Convert traps to pixman traps */
     if (num_traps > ARRAY_LENGTH(stack_traps)) {
 	pixman_traps = _cairo_malloc_ab (num_traps, sizeof(pixman_trapezoid_t));
-	if (pixman_traps == NULL)
+	if (pixman_traps == NULL) {
+	    _cairo_error (CAIRO_STATUS_SUCCESS);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     for (i = 0; i < num_traps; i++) {
@@ -1201,6 +1205,7 @@ _cairo_image_surface_composite_trapezoid
     mask_data = calloc (mask_stride, height);
     if (mask_data == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	goto CLEANUP_SOURCE;
     }
 
@@ -1208,6 +1213,7 @@ _cairo_image_surface_composite_trapezoid
 				     mask_data, mask_stride);
     if (mask == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	goto CLEANUP_IMAGE_DATA;
     }
 
diff --git a/src/cairo-lzw.c b/src/cairo-lzw.c
index 36a59fd..00aa71b 100644
--- a/src/cairo-lzw.c
+++ b/src/cairo-lzw.c
@@ -76,6 +76,7 @@ _lzw_buf_init (lzw_buf_t *buf, int size)
     if (buf->data == NULL) {
 	buf->data_size = 0;
 	buf->status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return;
     }
 }
@@ -102,6 +103,7 @@ _lzw_buf_grow (lzw_buf_t *buf)
 	free (buf->data);
 	buf->data_size = 0;
 	buf->status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return buf->status;
     }
 
diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c
index 5fcbf26..3fc61a8 100644
--- a/src/cairo-meta-surface.c
+++ b/src/cairo-meta-surface.c
@@ -252,8 +252,10 @@ _cairo_meta_surface_paint (void			*abstr
     cairo_command_paint_t *command;
 
     command = malloc (sizeof (cairo_command_paint_t));
-    if (command == NULL)
+    if (command == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     command->header.type = CAIRO_COMMAND_PAINT;
     command->header.region = CAIRO_META_REGION_ALL;
@@ -293,8 +295,10 @@ _cairo_meta_surface_mask (void			*abstra
     cairo_command_mask_t *command;
 
     command = malloc (sizeof (cairo_command_mask_t));
-    if (command == NULL)
+    if (command == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     command->header.type = CAIRO_COMMAND_MASK;
     command->header.region = CAIRO_META_REGION_ALL;
@@ -339,8 +343,10 @@ _cairo_meta_surface_stroke (void			*abst
     cairo_command_stroke_t *command;
 
     command = malloc (sizeof (cairo_command_stroke_t));
-    if (command == NULL)
+    if (command == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     command->header.type = CAIRO_COMMAND_STROKE;
     command->header.region = CAIRO_META_REGION_ALL;
@@ -394,8 +400,10 @@ _cairo_meta_surface_fill (void			*abstra
     cairo_command_fill_t *command;
 
     command = malloc (sizeof (cairo_command_fill_t));
-    if (command == NULL)
+    if (command == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     command->header.type = CAIRO_COMMAND_FILL;
     command->header.region = CAIRO_META_REGION_ALL;
@@ -441,8 +449,10 @@ _cairo_meta_surface_show_glyphs (void			
     cairo_command_show_glyphs_t *command;
 
     command = malloc (sizeof (cairo_command_show_glyphs_t));
-    if (command == NULL)
+    if (command == NULL) {
+	_cairo_error (CAIRO_STATUS_SUCCESS);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     command->header.type = CAIRO_COMMAND_SHOW_GLYPHS;
     command->header.region = CAIRO_META_REGION_ALL;
@@ -476,6 +486,7 @@ _cairo_meta_surface_show_glyphs (void			
     _cairo_pattern_fini (&command->source.base);
   CLEANUP_COMMAND:
     free (command);
+    _cairo_error (status);
     return status;
 }
 
@@ -531,8 +542,10 @@ _cairo_meta_surface_intersect_clip_path 
     cairo_status_t status;
 
     command = malloc (sizeof (cairo_command_intersect_clip_path_t));
-    if (command == NULL)
+    if (command == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     command->header.type = CAIRO_COMMAND_INTERSECT_CLIP_PATH;
     command->header.region = CAIRO_META_REGION_ALL;
@@ -799,6 +812,7 @@ _cairo_meta_surface_replay_internal (cai
 		dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t));
 		if (dev_glyphs == NULL) {
 		    status = CAIRO_STATUS_NO_MEMORY;
+		    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 		    break;
 		}
 		for (i = 0; i < num_glyphs; i++) {
diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c
index b9f0d38..a0add6d 100644
--- a/src/cairo-output-stream.c
+++ b/src/cairo-output-stream.c
@@ -119,8 +119,10 @@ _cairo_output_stream_create (cairo_write
     cairo_output_stream_with_closure_t *stream;
 
     stream = malloc (sizeof (cairo_output_stream_with_closure_t));
-    if (stream == NULL)
+    if (stream == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
+    }
 
     _cairo_output_stream_init (&stream->base, closure_write, closure_close);
     stream->write_func = write_func;
@@ -468,12 +470,16 @@ _cairo_output_stream_create_for_file (FI
 {
     stdio_stream_t *stream;
 
-    if (file == NULL)
+    if (file == NULL) {
+	_cairo_error (CAIRO_STATUS_WRITE_ERROR);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error;
+    }
 
     stream = malloc (sizeof *stream);
-    if (stream == NULL)
+    if (stream == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
+    }
 
     _cairo_output_stream_init (&stream->base, stdio_write, stdio_flush);
     stream->file = file;
@@ -488,12 +494,15 @@ _cairo_output_stream_create_for_filename
     FILE *file;
 
     file = fopen (filename, "wb");
-    if (file == NULL)
+    if (file == NULL) {
+	_cairo_error (CAIRO_STATUS_WRITE_ERROR);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error;
+    }
 
     stream = malloc (sizeof *stream);
     if (stream == NULL) {
 	fclose (file);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
     }
 
@@ -534,8 +543,10 @@ _cairo_memory_stream_create (void)
     memory_stream_t *stream;
 
     stream = malloc (sizeof *stream);
-    if (stream == NULL)
+    if (stream == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
+    }
 
     _cairo_output_stream_init (&stream->base, memory_write, memory_close);
     _cairo_array_init (&stream->array, 1);
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 007cc89..76eb661 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -76,8 +76,10 @@ _cairo_paginated_surface_create (cairo_s
     cairo_paginated_surface_t *surface;
 
     surface = malloc (sizeof (cairo_paginated_surface_t));
-    if (surface == NULL)
+    if (surface == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
+    }
 
     _cairo_surface_init (&surface->base, &cairo_paginated_surface_backend,
 			 content);
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index 7c8f34b..56b1df2 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -120,10 +120,14 @@ _cairo_path_fixed_init_copy (cairo_path_
 cairo_path_fixed_t *
 _cairo_path_fixed_create (void)
 {
-    cairo_path_fixed_t	*path = malloc (sizeof (cairo_path_fixed_t));
+    cairo_path_fixed_t	*path;
 
-    if (!path)
+    path = malloc (sizeof (cairo_path_fixed_t));
+    if (!path) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
+
     _cairo_path_fixed_init (path);
     return path;
 }
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index 7000197..0a295ba 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -1066,8 +1066,11 @@ _cairo_rectilinear_stroker_add_segment (
 	    new_size = 4;
 	new_segments = _cairo_realloc_ab (stroker->segments,
 	       	                          new_size, sizeof (cairo_line_t));
-	if (new_segments == NULL)
+	if (new_segments == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
+
 	stroker->segments_size = new_size;
 	stroker->segments = new_segments;
     }
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 1830634..eac7e4b 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -771,6 +771,7 @@ _cairo_pattern_gradient_grow (cairo_grad
     }
 
     if (new_stops == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
@@ -1160,8 +1161,10 @@ _cairo_pattern_acquire_surface_for_gradi
 
     if (pattern->n_stops > ARRAY_LENGTH(pixman_stops_static)) {
 	pixman_stops = _cairo_malloc_ab (pattern->n_stops, sizeof(pixman_gradient_stop_t));
-	if (pixman_stops == NULL)
+	if (pixman_stops == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     for (i = 0; i < pattern->n_stops; i++) {
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index fe4dd82..043d8f4 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1181,8 +1181,10 @@ compress_dup (const void *data, unsigned
     /* Bound calculation taken from zlib. */
     *compressed_size = data_size + (data_size >> 12) + (data_size >> 14) + 11;
     compressed = malloc (*compressed_size);
-    if (compressed == NULL)
+    if (compressed == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
 
     if (compress (compressed, compressed_size, data, data_size) != Z_OK) {
 	free (compressed);
@@ -1220,6 +1222,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf
     alpha = malloc (alpha_size);
     if (alpha == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP;
     }
 
@@ -1313,6 +1316,7 @@ _cairo_pdf_surface_emit_image (cairo_pdf
     rgb = malloc (rgb_size);
     if (rgb == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP;
     }
 
@@ -1884,8 +1888,10 @@ _cairo_pdf_surface_emit_pattern_stops (c
     alpha_function->id = 0;
 
     allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_pdf_color_stop_t));
-    if (allstops == NULL)
+    if (allstops == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     stops = &allstops[1];
     n_stops = pattern->n_stops;
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 27bf849..77d3820 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -149,8 +149,10 @@ _word_wrap_stream_create (cairo_output_s
     word_wrap_stream_t *stream;
 
     stream = malloc (sizeof (word_wrap_stream_t));
-    if (stream == NULL)
+    if (stream == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
+    }
 
     _cairo_output_stream_init (&stream->base,
 			       _word_wrap_stream_write,
@@ -1565,8 +1567,10 @@ _string_array_stream_create (cairo_outpu
     string_array_stream_t *stream;
 
     stream = malloc (sizeof (string_array_stream_t));
-    if (stream == NULL)
+    if (stream == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_output_stream_t *) &_cairo_output_stream_nil;
+    }
 
     _cairo_output_stream_init (&stream->base,
 			       _string_array_stream_write,
@@ -1647,6 +1651,7 @@ _cairo_ps_surface_emit_image (cairo_ps_s
     rgb = malloc (rgb_size);
     if (rgb == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto bail1;
     }
 
@@ -2117,8 +2122,10 @@ _cairo_ps_surface_stroke (void			*abstra
 	 */
 	if (num_dashes % 2) {
 	    dash = _cairo_malloc_abc (num_dashes, 2, sizeof (double));
-	    if (dash == NULL)
+	    if (dash == NULL) {
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
 		return CAIRO_STATUS_NO_MEMORY;
+	    }
 
 	    memcpy (dash, style->dash, num_dashes * sizeof (double));
 	    memcpy (dash + num_dashes, style->dash, num_dashes * sizeof (double));
@@ -2299,8 +2306,10 @@ _cairo_ps_surface_show_glyphs (void		   
 
     _cairo_ps_surface_emit_pattern (surface, source);
     glyph_ids = _cairo_malloc_ab (num_glyphs_unsigned, sizeof (cairo_ps_glyph_id_t));
-    if (glyph_ids == NULL)
-        return CAIRO_STATUS_NO_MEMORY;
+    if (glyph_ids == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     for (i = 0; i < num_glyphs_unsigned; i++) {
         status = _cairo_scaled_font_subsets_map_glyph (surface->font_subsets,
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 540bdca..8a90f30 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1256,6 +1256,10 @@ _cairo_quartz_surface_stroke (void *abst
 	unsigned int k;
 	if (style->num_dashes > STATIC_DASH)
 	    fdash = _cairo_malloc_ab (style->num_dashes, sizeof (float));
+	if (fdash == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return CAIRO_STATUS_NO_MEMORY;
+	}
 
 	for (k = 0; k < style->num_dashes; k++)
 	    fdash[k] = (float) style->dash[k];
@@ -1395,7 +1399,17 @@ _cairo_quartz_surface_show_glyphs (void 
 
     if (num_glyphs > STATIC_BUF_SIZE) {
 	cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof(CGGlyph));
+	if (cg_glyphs == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return CAIRO_STATUS_NO_MEMORY;
+	}
+
 	cg_advances = (CGSize*) _cairo_malloc_ab (num_glyphs, sizeof(CGSize));
+	if (cg_glyphs == NULL) {
+	    free (cg_advances);
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     xprev = glyphs[0].x;
diff --git a/src/cairo-region.c b/src/cairo-region.c
index e5889c7..ea4ccc3 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -66,8 +66,10 @@ _cairo_region_init_boxes (cairo_region_t
 
     if (count > ARRAY_LENGTH(stack_pboxes)) {
 	pboxes = _cairo_malloc_ab (count, sizeof(pixman_box16_t));
-	if (pboxes == NULL)
+	if (pboxes == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     for (i = 0; i < count; i++) {
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index ea2e63a..a5d9c49 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -124,8 +124,10 @@ _cairo_sub_font_glyph_create (unsigned l
     cairo_sub_font_glyph_t *sub_font_glyph;
 
     sub_font_glyph = malloc (sizeof (cairo_sub_font_glyph_t));
-    if (sub_font_glyph == NULL)
+    if (sub_font_glyph == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
 
     _cairo_sub_font_glyph_init_key (sub_font_glyph, scaled_font_glyph_index);
     sub_font_glyph->subset_id = subset_id;
@@ -214,8 +216,10 @@ _cairo_sub_font_create (cairo_scaled_fon
     cairo_sub_font_t *sub_font;
 
     sub_font = malloc (sizeof (cairo_sub_font_t));
-    if (sub_font == NULL)
+    if (sub_font == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
 
     sub_font->is_scaled = is_scaled;
     sub_font->is_composite = is_composite;
@@ -410,9 +414,11 @@ _cairo_scaled_font_subsets_create_intern
 {
     cairo_scaled_font_subsets_t *subsets;
 
-    subsets = malloc (sizeof (cairo_scaled_font_subsets_t));
-    if (subsets == NULL)
+    subsets = malloc (sizeof (cairo_scaled_font_subsets_t)); 
+    if (subsets == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
 
     subsets->type = type;
     subsets->max_glyphs_per_unscaled_subset_used = 0;
@@ -623,8 +629,10 @@ _cairo_scaled_font_subsets_foreach_inter
 	return CAIRO_STATUS_SUCCESS;
 
     collection.glyphs = _cairo_malloc_ab (collection.glyphs_size, sizeof(unsigned long));
-    if (collection.glyphs == NULL)
+    if (collection.glyphs == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     collection.font_subset_callback = font_subset_callback;
     collection.font_subset_callback_closure = closure;
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index f3808c9..282a486 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -324,6 +324,7 @@ _cairo_scaled_font_map_lock (void)
     cairo_scaled_font_map = NULL;
  CLEANUP_MUTEX_LOCK:
     CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex);
+    _cairo_error (CAIRO_STATUS_NO_MEMORY);
     return NULL;
 }
 
@@ -1036,6 +1037,7 @@ _cairo_scaled_font_text_to_glyphs (cairo
 
     if (*glyphs == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto DONE;
     }
 
@@ -1626,6 +1628,7 @@ _cairo_scaled_glyph_lookup (cairo_scaled
 	scaled_glyph = malloc (sizeof (cairo_scaled_glyph_t));
 	if (scaled_glyph == NULL) {
 	    status = CAIRO_STATUS_NO_MEMORY;
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto CLEANUP;
 	}
 
diff --git a/src/cairo-skiplist.c b/src/cairo-skiplist.c
index 72ca6ce..fe80263 100644
--- a/src/cairo-skiplist.c
+++ b/src/cairo-skiplist.c
@@ -355,8 +355,11 @@ _cairo_skip_list_insert (cairo_skip_list
     }
 
     data_and_elt = alloc_node_for_level (list, level);
-    if (data_and_elt == NULL)
+    if (data_and_elt == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
+
     memcpy (data_and_elt, data, list->data_size);
     elt = (skip_elt_t *) (data_and_elt + list->data_size);
 
diff --git a/src/cairo-spline.c b/src/cairo-spline.c
index 70c4ede..f22f646 100644
--- a/src/cairo-spline.c
+++ b/src/cairo-spline.c
@@ -118,6 +118,7 @@ _cairo_spline_grow (cairo_spline_t *spli
     }
 
     if (new_points == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
diff --git a/src/cairo-stroke-style.c b/src/cairo-stroke-style.c
index 2eccb80..ea6b412 100644
--- a/src/cairo-stroke-style.c
+++ b/src/cairo-stroke-style.c
@@ -63,8 +63,10 @@ _cairo_stroke_style_init_copy (cairo_str
 	style->dash = NULL;
     } else {
 	style->dash = _cairo_malloc_ab (style->num_dashes, sizeof (double));
-	if (style->dash == NULL)
+	if (style->dash == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
 
 	memcpy (style->dash, other->dash,
 		style->num_dashes * sizeof (double));
diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index ab19d2c..37aee51 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -1172,6 +1172,7 @@ _cairo_surface_fallback_fill_rectangles 
 	offset_rects = _cairo_malloc_ab (num_rects, sizeof (cairo_rectangle_int_t));
 	if (offset_rects == NULL) {
 	    status = CAIRO_STATUS_NO_MEMORY;
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto DONE;
 	}
 
@@ -1228,6 +1229,7 @@ _cairo_surface_fallback_composite_trapez
 	offset_traps = _cairo_malloc_ab (num_traps, sizeof (cairo_trapezoid_t));
 	if (!offset_traps) {
 	    status = CAIRO_STATUS_NO_MEMORY;
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto DONE;
 	}
 
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 05dc906..b5fcc64 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -1268,6 +1268,7 @@ _cairo_surface_fill_region (cairo_surfac
 	rects = _cairo_malloc_ab (num_boxes, sizeof (cairo_rectangle_int_t));
 	if (!rects) {
 	    _cairo_region_boxes_fini (region, boxes);
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
         }
     }
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 8abd4dd..32743b4 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -270,6 +270,7 @@ _cairo_traps_grow (cairo_traps_t *traps)
     }
 
     if (new_traps == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	traps->status = CAIRO_STATUS_NO_MEMORY;
 	return traps->status;
     }
@@ -614,8 +615,10 @@ _cairo_traps_extract_region (cairo_traps
     if (traps->num_traps > ARRAY_LENGTH(stack_boxes)) {
 	boxes = _cairo_malloc_ab (traps->num_traps, sizeof(cairo_box_int_t));
 
-	if (boxes == NULL)
+	if (boxes == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     box_count = 0;
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 83f35fd..5afab3a 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -270,6 +270,7 @@ _cairo_truetype_font_create (cairo_scale
     if (name)
 	free (name);
 
+    _cairo_error (status);
     return status;
 }
 
@@ -511,6 +512,7 @@ cairo_truetype_font_write_glyf_table (ca
     u.bytes = malloc (size);
     if (u.bytes == NULL) {
 	font->status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return font->status;
     }
 
@@ -1038,6 +1040,7 @@ _cairo_truetype_subset_init (cairo_truet
  fail1:
     cairo_truetype_font_destroy (font);
 
+    _cairo_error (status);
     return status;
 }
 
@@ -1083,8 +1086,11 @@ _cairo_truetype_map_glyphs_to_unicode (c
 
     size = be16_to_cpu (map->length);
     map = malloc (size);
-    if (map == NULL)
+    if (map == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
+
     if (backend->load_truetype_table (font_subset->scaled_font,
                                       TT_TAG_cmap, table_offset,
                                       (unsigned char *) map,
@@ -1167,8 +1173,11 @@ _cairo_truetype_create_glyph_to_unicode_
     num_tables = be16_to_cpu (cmap->num_tables);
     size = 4 + num_tables*sizeof(tt_cmap_index_t);
     cmap = malloc (size);
-    if (cmap == NULL)
+    if (cmap == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
+
     if (backend->load_truetype_table (font_subset->scaled_font,
                                       TT_TAG_cmap, 0, (unsigned char *) cmap,
                                       &size) != CAIRO_STATUS_SUCCESS) {
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 3872777..564b4b0 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -80,13 +80,16 @@ cairo_type1_font_create (cairo_scaled_fo
     cairo_font_options_t font_options;
 
     font = calloc (1, sizeof (cairo_type1_font_t));
-    if (font == NULL)
+    if (font == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font->widths = calloc (scaled_font_subset->num_glyphs,
                            sizeof (int));
     if (font->widths == NULL) {
 	free (font);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
@@ -781,6 +784,7 @@ _cairo_type1_fallback_init_internal (cai
     /* status is already set, ignore further errors */
     cairo_type1_font_destroy (font);
 
+    _cairo_error (status);
     return status;
 }
 
@@ -873,6 +877,7 @@ fail2:
     _cairo_type2_charstrings_fini (type2_subset);
 fail1:
     cairo_type1_font_destroy (font);
+    _cairo_error (status);
     return status;
 }
 
diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index 0716005..793faf3 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -119,6 +119,8 @@ _cairo_type1_font_subset_create (cairo_u
     ft_unscaled_font = (cairo_ft_unscaled_font_t *) unscaled_font;
 
     face = _cairo_ft_unscaled_font_lock_face (ft_unscaled_font);
+    if (!face)
+	return CAIRO_STATUS_NO_MEMORY;
 
     if (FT_Get_PS_Font_Info(face, &font_info) != 0) {
 	status = CAIRO_INT_STATUS_UNSUPPORTED;
@@ -179,6 +181,8 @@ _cairo_type1_font_subset_create (cairo_u
  fail1:
     _cairo_ft_unscaled_font_unlock_face (ft_unscaled_font);
 
+    if (status != CAIRO_INT_STATUS_UNSUPPORTED)
+	_cairo_error (status);
     return status;
 }
 
@@ -368,10 +372,12 @@ cairo_type1_font_subset_decrypt_eexec_se
     end = (unsigned char *) in + font->eexec_segment_size;
 
     font->cleartext = malloc (font->eexec_segment_size);
-    if (font->cleartext == NULL)
+    if (font->cleartext == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return font->status = CAIRO_STATUS_NO_MEMORY;
-    out = font->cleartext;
+    }
 
+    out = font->cleartext;
     while (in < end) {
 	if (font->eexec_segment_is_ascii) {
 	    c = *in++;
@@ -386,7 +392,6 @@ cairo_type1_font_subset_decrypt_eexec_se
 
 	*out++ = p;
     }
-
     font->cleartext_end = out;
 
     return font->status;
@@ -714,8 +719,10 @@ cairo_type1_font_subset_look_for_seac(ca
     int command;
 
     charstring = malloc (encrypted_charstring_length);
-    if (charstring == NULL)
+    if (charstring == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return;
+    }
 
     cairo_type1_font_subset_decrypt_charstring ((const unsigned char *)
 						encrypted_charstring,
@@ -1041,15 +1048,20 @@ cairo_type1_font_subset_generate (void  
     unsigned long ret;
 
     ft_unscaled_font = (cairo_ft_unscaled_font_t *) font->base.unscaled_font;
-    font->face = _cairo_ft_unscaled_font_lock_face (ft_unscaled_font);
 
     /* If anything fails below, it's out of memory. */
     font->status = CAIRO_STATUS_NO_MEMORY;
 
+    font->face = _cairo_ft_unscaled_font_lock_face (ft_unscaled_font);
+    if (!font->face)
+	return CAIRO_STATUS_NO_MEMORY;
+
     font->type1_length = font->face->stream->size;
     font->type1_data = malloc (font->type1_length);
-    if (font->type1_data == NULL)
+    if (font->type1_data == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail;
+    }
 
     if (font->face->stream->read) {
 	ret = font->face->stream->read (font->face->stream, 0,
@@ -1184,6 +1196,8 @@ _cairo_type1_subset_init (cairo_type1_su
  fail1:
     cairo_type1_font_subset_destroy (font);
 
+    if (status != CAIRO_INT_STATUS_UNSUPPORTED)
+	_cairo_error (status);
     return status;
 }
 
diff --git a/src/cairo-unicode.c b/src/cairo-unicode.c
index 1d1c00a..8ee6d24 100644
--- a/src/cairo-unicode.c
+++ b/src/cairo-unicode.c
@@ -241,8 +241,10 @@ _cairo_utf8_to_ucs4 (const unsigned char
     }
 
     str32 = _cairo_malloc_ab (n_chars + 1, sizeof (uint32_t));
-    if (!str32)
+    if (!str32) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     in = str;
     for (i=0; i < n_chars; i++) {
@@ -308,8 +310,10 @@ _cairo_utf8_to_utf16 (const unsigned cha
     }
 
     str16 = _cairo_malloc_ab (n16 + 1, sizeof (uint16_t));
-    if (!str16)
+    if (!str16) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     in = str;
     for (i = 0; i < n16;) {
diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index 81213e7..a883490 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -246,8 +246,10 @@ _win32_scaled_font_create (LOGFONTW     
     cairo_status_t status;
 
     f = malloc (sizeof(cairo_win32_scaled_font_t));
-    if (f == NULL)
+    if (f == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
+    }
 
     f->logfont = *logfont;
 
@@ -412,8 +414,10 @@ _win32_scaled_font_get_unscaled_hfont (c
 	}
 
 	otm = malloc (otm_size);
-	if (!otm)
+	if (!otm) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return NULL;
+	}
 
 	if (!GetOutlineTextMetrics (hdc, otm_size, otm)) {
 	    _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:GetOutlineTextMetrics");
@@ -691,6 +695,7 @@ _cairo_win32_scaled_font_text_to_glyphs 
  FAIL1:
     free (utf16);
 
+    _cairo_error (status);
     return status;
 }
 
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index 1b1a2ff..4b27a8d 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -187,8 +187,10 @@ _create_dc_and_bitmap (cairo_win32_surfa
 
     if (num_palette > 2) {
 	bitmap_info = _cairo_malloc_ab_plus_c (num_palette, sizeof(RGBQUAD), sizeof(BITMAPINFOHEADER));
-	if (!bitmap_info)
+	if (!bitmap_info) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
+	}
     } else {
 	bitmap_info = (BITMAPINFO *)&bmi_stack;
     }
@@ -1467,6 +1469,7 @@ _cairo_win32_surface_set_clip_region (vo
 	data = malloc (data_size);
 	if (!data) {
 	    _cairo_region_boxes_fini (region, boxes);
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
 	}
 	rects = (RECT *)data->Buffer;
diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
index bcdadae..d5c27d6 100644
--- a/src/cairo-xcb-surface.c
+++ b/src/cairo-xcb-surface.c
@@ -406,6 +406,7 @@ _get_image_surface (cairo_xcb_surface_t 
     data = _cairo_malloc_ab (surface->height, bytes_per_line);
     if (data == NULL) {
 	free (imagerep);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
@@ -1265,8 +1266,10 @@ _cairo_xcb_surface_fill_rectangles (void
 
     if (num_rects > ARRAY_LENGTH(static_xrects)) {
         xrects = _cairo_malloc_ab (num_rects, sizeof(xcb_rectangle_t));
-        if (xrects == NULL)
-            return CAIRO_STATUS_NO_MEMORY;
+	if (xrects == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     for (i = 0; i < num_rects; i++) {
@@ -1347,8 +1350,10 @@ _create_trapezoid_mask (cairo_xcb_surfac
     solid_picture = _create_a8_picture (dst, &solid, width, height, TRUE);
 
     offset_traps = _cairo_malloc_ab (num_traps, sizeof (xcb_render_trapezoid_t));
-    if (!offset_traps)
+    if (!offset_traps) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return XCB_NONE;
+    }
 
     for (i = 0; i < num_traps; i++) {
 	offset_traps[i].top = _cairo_fixed_to_16_16(traps[i].top) - 0x10000 * dst_y;
@@ -1496,6 +1501,7 @@ _cairo_xcb_surface_composite_trapezoids 
             xtraps = _cairo_malloc_ab (num_traps, sizeof(xcb_render_trapezoid_t));
             if (xtraps == NULL) {
                 status = CAIRO_STATUS_NO_MEMORY;
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
                 goto BAIL;
             }
         }
@@ -1565,6 +1571,7 @@ _cairo_xcb_surface_set_clip_region (void
 	    rects = _cairo_malloc_ab (n_boxes, sizeof(xcb_rectangle_t));
 	    if (rects == NULL) {
                 _cairo_region_boxes_fini (region, boxes);
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
 		return CAIRO_STATUS_NO_MEMORY;
             }
 	} else {
@@ -1989,8 +1996,10 @@ _cairo_xcb_surface_font_init (xcb_connec
     cairo_xcb_surface_font_private_t	*font_private;
 
     font_private = malloc (sizeof (cairo_xcb_surface_font_private_t));
-    if (!font_private)
+    if (!font_private) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     font_private->dpy = dpy;
     font_private->format = format;
@@ -2109,6 +2118,7 @@ _cairo_xcb_surface_add_glyph (xcb_connec
 	    new = malloc (c);
 	    if (!new) {
 		status = CAIRO_STATUS_NO_MEMORY;
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
 		goto BAIL;
 	    }
 	    n = new;
@@ -2135,6 +2145,7 @@ _cairo_xcb_surface_add_glyph (xcb_connec
 	    new = malloc (c);
 	    if (new == NULL) {
 		status = CAIRO_STATUS_NO_MEMORY;
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
 		goto BAIL;
 	    }
 	    n = new;
@@ -2374,8 +2385,10 @@ _cairo_xcb_surface_show_glyphs (void    
      * glyphs to workaround an X server bug, (present in at least Xorg
      * 7.1 without EXA). */
     output_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t));
-    if (output_glyphs == NULL)
+    if (output_glyphs == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     /* After passing all those tests, we're now committed to rendering
      * these glyphs or to fail trying. We first upload any glyphs to
diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index 673c546..6e8f2ba 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -251,8 +251,10 @@ _cairo_xlib_display_get (Display *dpy)
     }
 
     display = malloc (sizeof (cairo_xlib_display_t));
-    if (display == NULL)
+    if (display == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto UNLOCK;
+    }
 
     /* Xlib calls out to the extension close_display hooks in LIFO
      * order. So we have to ensure that all extensions that we depend
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 9478594..65e2d6a 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -1445,8 +1445,10 @@ _cairo_xlib_surface_fill_rectangles (voi
 
     if (num_rects > ARRAY_LENGTH(static_xrects)) {
         xrects = _cairo_malloc_ab (num_rects, sizeof(XRectangle));
-        if (xrects == NULL)
-            return CAIRO_STATUS_NO_MEMORY;
+	if (xrects == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return CAIRO_STATUS_NO_MEMORY;
+	}
     }
 
     for (i = 0; i < num_rects; i++) {
@@ -1534,6 +1536,7 @@ _create_trapezoid_mask (cairo_xlib_surfa
     offset_traps = _cairo_malloc_ab (num_traps, sizeof (XTrapezoid));
     if (!offset_traps) {
 	XRenderFreePicture (dst->dpy, mask_picture);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return None;
     }
 
@@ -1684,6 +1687,7 @@ _cairo_xlib_surface_composite_trapezoids
             xtraps = _cairo_malloc_ab (num_traps, sizeof(XTrapezoid));
             if (xtraps == NULL) {
                 status = CAIRO_STATUS_NO_MEMORY;
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
                 goto BAIL;
             }
         }
@@ -1748,6 +1752,7 @@ _cairo_xlib_surface_set_clip_region (voi
 	    rects = _cairo_malloc_ab (n_boxes, sizeof(XRectangle));
 	    if (rects == NULL) {
                 _cairo_region_boxes_fini (region, boxes);
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
 		return CAIRO_STATUS_NO_MEMORY;
             }
 	} else {
@@ -2451,13 +2456,16 @@ _cairo_xlib_surface_font_init (Display		
     cairo_xlib_surface_font_private_t	*font_private;
 
     font_private = malloc (sizeof (cairo_xlib_surface_font_private_t));
-    if (!font_private)
+    if (!font_private) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     if (!_cairo_xlib_add_close_display_hook (dpy,
 		_cairo_xlib_surface_remove_scaled_font,
 		scaled_font, scaled_font)) {
 	free (font_private);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
@@ -2642,6 +2650,7 @@ _cairo_xlib_surface_add_glyph (Display *
 
 	    new = malloc (c);
 	    if (new == NULL) {
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
 		status = CAIRO_STATUS_NO_MEMORY;
 		goto BAIL;
 	    }
@@ -2769,8 +2778,10 @@ _cairo_xlib_surface_emit_glyphs_chunk (c
       elts = stack_elts;
     } else {
       elts = _cairo_malloc_ab (num_elts, sizeof (XGlyphElt8));
-      if (elts == NULL)
+      if (elts == NULL) {
+	  _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	  return CAIRO_STATUS_NO_MEMORY;
+      }
     }
 
     /* Fill them in */
diff --git a/src/cairo.c b/src/cairo.c
index 8652b28..4e3bfda 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -196,8 +196,10 @@ cairo_create (cairo_surface_t *target)
 	return (cairo_t *) &_cairo_nil;
 
     cr = malloc (sizeof (cairo_t));
-    if (cr == NULL)
+    if (cr == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_t *) &_cairo_nil;
+    }
 
     CAIRO_REFERENCE_COUNT_INIT (&cr->ref_count, 1);
 
@@ -2414,8 +2416,11 @@ _cairo_rectangle_list_create_in_error (c
         return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
 
     list = malloc (sizeof (cairo_rectangle_list_t));
-    if (list == NULL)
+    if (list == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
+    }
+
     list->status = status;
     list->rectangles = NULL;
     list->num_rectangles = 0;
diff --git a/src/test-meta-surface.c b/src/test-meta-surface.c
index 3992b4c..82fde5f 100644
--- a/src/test-meta-surface.c
+++ b/src/test-meta-surface.c
@@ -76,8 +76,10 @@ _cairo_test_meta_surface_create (cairo_c
     test_meta_surface_t *surface;
 
     surface = malloc (sizeof (test_meta_surface_t));
-    if (surface == NULL)
+    if (surface == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
+    }
 
     _cairo_surface_init (&surface->base, &test_meta_surface_backend,
 			 content);
diff-tree 66664596559c55913fb0b9c8784fe8ab862c217b (from e49bcde27f88e21d5b8037a0089a226096f6514b)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Oct 3 23:25:10 2007 +0100

    [malloc] Take advantage of calloc() argument checking.
    
    calloc() will check its arguments for integer overflows so it is safer
    not to pre-multiply them.

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 3262163..38a4a8d 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -840,7 +840,7 @@ _get_bitmap_surface (FT_Bitmap		     *bi
 	    width_rgba = width;
 	    stride = bitmap->pitch;
 	    stride_rgba = (width_rgba * 4 + 3) & ~3;
-	    data_rgba = calloc (1, stride_rgba * height);
+	    data_rgba = calloc (stride_rgba, height);
 	    if (data_rgba == NULL) {
 		if (own_buffer)
 		    free (bitmap->buffer);
@@ -1041,7 +1041,7 @@ _render_glyph_outline (FT_Face          
 	bitmap.pitch = stride;
 	bitmap.width = width * hmul;
 	bitmap.rows = height * vmul;
-	bitmap.buffer = calloc (1, stride * bitmap.rows);
+	bitmap.buffer = calloc (stride, bitmap.rows);
 
 	if (bitmap.buffer == NULL) {
 	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c
index 8f497a9..4b0e74b 100644
--- a/src/cairo-glitz-surface.c
+++ b/src/cairo-glitz-surface.c
@@ -1347,7 +1347,7 @@ _cairo_glitz_surface_composite_trapezoid
 	int		      stride;
 
 	stride = (width + 3) & -4;
-	data = calloc (stride * height, 1);
+	data = calloc (stride, height);
 	if (!data)
 	{
 	    _cairo_glitz_pattern_release_surface (src_pattern, src, &attributes);
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 6459329..9fbdb59 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1198,7 +1198,7 @@ _cairo_image_surface_composite_trapezoid
     }
 
     /* The image must be initially transparent */
-    mask_data = calloc (1, mask_stride * height);
+    mask_data = calloc (mask_stride, height);
     if (mask_data == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
 	goto CLEANUP_SOURCE;
diff-tree e49bcde27f88e21d5b8037a0089a226096f6514b (from 8cba73a36c4ec42601388bb9374f3182651bfe60)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Oct 3 23:19:10 2007 +0100

    [malloc] Check for integer overflow when realloc'ing.
    
    Perform similar sanity checks to Vlad's _cairo_malloc_ab() but on the
    arguments to realloc instead.

diff --git a/src/cairo-array.c b/src/cairo-array.c
index ff8cce4..3525c78 100644
--- a/src/cairo-array.c
+++ b/src/cairo-array.c
@@ -138,8 +138,8 @@ _cairo_array_grow_by (cairo_array_t *arr
     }
 
     array->size = new_size;
-    new_elements = realloc (*array->elements,
-			    array->size * array->element_size);
+    new_elements = _cairo_realloc_ab (*array->elements,
+			              array->size, array->element_size);
 
     if (new_elements == NULL) {
 	array->size = old_size;
diff --git a/src/cairo-lzw.c b/src/cairo-lzw.c
index 370d258..36a59fd 100644
--- a/src/cairo-lzw.c
+++ b/src/cairo-lzw.c
@@ -93,7 +93,11 @@ _lzw_buf_grow (lzw_buf_t *buf)
     if (buf->status)
 	return buf->status;
 
-    new_data = realloc (buf->data, new_size);
+    new_data = NULL;
+    /* check for integer overflow */
+    if (new_size / 2 == buf->data_size)
+	new_data = realloc (buf->data, new_size);
+
     if (new_data == NULL) {
 	free (buf->data);
 	buf->data_size = 0;
diff --git a/src/cairo-malloc-private.h b/src/cairo-malloc-private.h
index ad22851..f8094f9 100644
--- a/src/cairo-malloc-private.h
+++ b/src/cairo-malloc-private.h
@@ -59,7 +59,7 @@
  * @n: number of elements to allocate
  * @size: size of each element
  *
- * Allocates @a*@size memory using _cairo_malloc(), taking care to not
+ * Allocates @n*@size memory using _cairo_malloc(), taking care to not
  * overflow when doing the multiplication.  Behaves much like
  * calloc(), except that the returned memory is not set to zero.
  * The memory should be freed using free().
@@ -76,12 +76,34 @@
    _cairo_malloc((unsigned) (a) * (unsigned) (size)))
 
 /**
+ * _cairo_realloc_ab:
+ * @ptr: original pointer to block of memory to be resized
+ * @n: number of elements to allocate
+ * @size: size of each element
+ *
+ * Reallocates @ptr a block of @n*@size memory using realloc(), taking
+ * care to not overflow when doing the multiplication.  The memory
+ * should be freed using free().
+ *
+ * @size should be a constant so that the compiler can optimize
+ * out a constant division.
+ *
+ * Return value: A pointer to the newly allocated memory, or %NULL in
+ * case of realloc() failure or overflow (whereupon the original block
+ * of memory * is left untouched).
+ */
+
+#define _cairo_realloc_ab(ptr, a, size) \
+  ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \
+   realloc(ptr, (unsigned) (a) * (unsigned) (size)))
+
+/**
  * _cairo_malloc_abc:
- * @a: first factor of number of elements to allocate
+ * @n: first factor of number of elements to allocate
  * @b: second factor of number of elements to allocate
  * @size: size of each element
  *
- * Allocates @a*@b*@size memory using _cairo_malloc(), taking care to not
+ * Allocates @n*@b*@size memory using _cairo_malloc(), taking care to not
  * overflow when doing the multiplication.  Behaves like
  * _cairo_malloc_ab().  The memory should be freed using free().
  *
@@ -103,7 +125,7 @@
  * @size: size of each element
  * @k: additional size to allocate
  *
- * Allocates @a*@ksize+ at k memory using _cairo_malloc(), taking care to not
+ * Allocates @n*@ksize+ at k memory using _cairo_malloc(), taking care to not
  * overflow when doing the arithmetic.  Behaves like
  * _cairo_malloc_ab().  The memory should be freed using free().
  *
diff --git a/src/cairo-path-stroke.c b/src/cairo-path-stroke.c
index d8d989b..7000197 100644
--- a/src/cairo-path-stroke.c
+++ b/src/cairo-path-stroke.c
@@ -1064,7 +1064,8 @@ _cairo_rectilinear_stroker_add_segment (
 	/* Common case is one rectangle of exactly 4 segments. */
 	if (new_size == 0)
 	    new_size = 4;
-	new_segments = realloc (stroker->segments, new_size * sizeof (cairo_line_t));
+	new_segments = _cairo_realloc_ab (stroker->segments,
+	       	                          new_size, sizeof (cairo_line_t));
 	if (new_segments == NULL)
 	    return CAIRO_STATUS_NO_MEMORY;
 	stroker->segments_size = new_size;
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 231f5b2..1830634 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -765,7 +765,9 @@ _cairo_pattern_gradient_grow (cairo_grad
 	if (new_stops)
 	    memcpy (new_stops, pattern->stops, old_size * sizeof (cairo_gradient_stop_t));
     } else {
-	new_stops = realloc (pattern->stops, new_size * sizeof (cairo_gradient_stop_t));
+	new_stops = _cairo_realloc_ab (pattern->stops,
+	       	                       new_size,
+				       sizeof (cairo_gradient_stop_t));
     }
 
     if (new_stops == NULL) {
diff --git a/src/cairo-pen.c b/src/cairo-pen.c
index 8d5401d..471849b 100644
--- a/src/cairo-pen.c
+++ b/src/cairo-pen.c
@@ -142,7 +142,8 @@ _cairo_pen_add_points (cairo_pen_t *pen,
     int i;
 
     num_vertices = pen->num_vertices + num_points;
-    vertices = realloc (pen->vertices, num_vertices * sizeof (cairo_pen_vertex_t));
+    vertices = _cairo_realloc_ab (pen->vertices,
+	                          num_vertices, sizeof (cairo_pen_vertex_t));
     if (vertices == NULL) {
 	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c
index 7128e4b..3aa0c4c 100644
--- a/src/cairo-polygon.c
+++ b/src/cairo-polygon.c
@@ -97,7 +97,8 @@ _cairo_polygon_grow (cairo_polygon_t *po
 	if (new_edges)
 	    memcpy (new_edges, polygon->edges, old_size * sizeof (cairo_edge_t));
     } else {
-	new_edges = realloc (polygon->edges, new_size * sizeof (cairo_edge_t));
+	new_edges = _cairo_realloc_ab (polygon->edges,
+	       	                       new_size, sizeof (cairo_edge_t));
     }
 
     if (new_edges == NULL) {
diff --git a/src/cairo-spline.c b/src/cairo-spline.c
index db748b3..70c4ede 100644
--- a/src/cairo-spline.c
+++ b/src/cairo-spline.c
@@ -113,7 +113,8 @@ _cairo_spline_grow (cairo_spline_t *spli
 	if (new_points)
 	    memcpy (new_points, spline->points, old_size * sizeof (cairo_point_t));
     } else {
-	new_points = realloc (spline->points, new_size * sizeof (cairo_point_t));
+	new_points = _cairo_realloc_ab (spline->points,
+	       	                        new_size, sizeof (cairo_point_t));
     }
 
     if (new_points == NULL) {
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 0a1ccbe..8abd4dd 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -265,7 +265,8 @@ _cairo_traps_grow (cairo_traps_t *traps)
 	if (new_traps)
 	    memcpy (new_traps, traps->traps, sizeof (traps->traps_embedded));
     } else {
-	new_traps = realloc (traps->traps, new_size * sizeof (cairo_trapezoid_t));
+	new_traps = _cairo_realloc_ab (traps->traps,
+	       	                       new_size, sizeof (cairo_trapezoid_t));
     }
 
     if (new_traps == NULL) {
diff-tree 8cba73a36c4ec42601388bb9374f3182651bfe60 (from e767c8b50af578209f1dac3b8f2ae22835e1fee7)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Oct 3 22:27:09 2007 +0100

    [cairo-polygon] Add a _cairo_error().
    
    Add a _cairo_error() to an originating error site.

diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c
index 726884a..7128e4b 100644
--- a/src/cairo-polygon.c
+++ b/src/cairo-polygon.c
@@ -101,6 +101,7 @@ _cairo_polygon_grow (cairo_polygon_t *po
     }
 
     if (new_edges == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
diff-tree e767c8b50af578209f1dac3b8f2ae22835e1fee7 (from 7047a091748577754845a6ed7f35837e41e7d5fb)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Oct 3 22:26:03 2007 +0100

    [cairo-pen] Add _cairo_error().
    
    Markup a couple of originating error sites with _cairo_error().

diff --git a/src/cairo-pen.c b/src/cairo-pen.c
index 0ff01f3..8d5401d 100644
--- a/src/cairo-pen.c
+++ b/src/cairo-pen.c
@@ -78,8 +78,10 @@ _cairo_pen_init (cairo_pen_t	*pen,
 						    radius,
 						    ctm);
 
-    pen->vertices = _cairo_malloc_ab (pen->num_vertices, sizeof (cairo_pen_vertex_t));
+    pen->vertices = _cairo_malloc_ab (pen->num_vertices,
+	                              sizeof (cairo_pen_vertex_t));
     if (pen->vertices == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
     }
 
@@ -119,8 +121,10 @@ _cairo_pen_init_copy (cairo_pen_t *pen, 
     *pen = *other;
 
     if (pen->num_vertices) {
-	pen->vertices = _cairo_malloc_ab (pen->num_vertices, sizeof (cairo_pen_vertex_t));
+	pen->vertices = _cairo_malloc_ab (pen->num_vertices,
+	       	                          sizeof (cairo_pen_vertex_t));
 	if (pen->vertices == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return CAIRO_STATUS_NO_MEMORY;
 	}
 	memcpy (pen->vertices, other->vertices, pen->num_vertices * sizeof (cairo_pen_vertex_t));
@@ -139,8 +143,10 @@ _cairo_pen_add_points (cairo_pen_t *pen,
 
     num_vertices = pen->num_vertices + num_points;
     vertices = realloc (pen->vertices, num_vertices * sizeof (cairo_pen_vertex_t));
-    if (vertices == NULL)
+    if (vertices == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     pen->vertices = vertices;
     pen->num_vertices = num_vertices;


More information about the cairo-commit mailing list