[cairo-commit] 3 commits - src/cairo-quartz-surface.c

Brian Ewins brianewins at kemper.freedesktop.org
Mon Nov 12 15:58:35 PST 2007


 src/cairo-quartz-surface.c |   35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

New commits:
commit bb2674207cf01386c6338511d2462694187fff36
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Mon Nov 12 23:56:01 2007 +0000

    [quartz] fix leak in show_glyphs
    
    In cairo_quartz_show_glyphs we may leak the source if
    there is a failure to malloc the glyph arrays. Fix this.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 126a291..5abbffa 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1461,8 +1461,8 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
 	CGContextSetTextDrawingMode (surface->cgContext, kCGTextClip);
     } else {
 	/* Unsupported */
-	CGContextRestoreGState (surface->cgContext);
-	return CAIRO_INT_STATUS_UNSUPPORTED;
+	rv = CAIRO_INT_STATUS_UNSUPPORTED;
+	goto BAIL;
     }
 
     CGContextSetCompositeOperation (surface->cgContext, _cairo_quartz_cairo_operator_to_quartz (op));
@@ -1502,13 +1502,15 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
 
     if (num_glyphs > STATIC_BUF_SIZE) {
 	cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof(CGGlyph));
-	if (cg_glyphs == NULL)
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	if (cg_glyphs == NULL) {
+	    rv = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    goto BAIL;
+	}
 
 	cg_advances = (CGSize*) _cairo_malloc_ab (num_glyphs, sizeof(CGSize));
 	if (cg_glyphs == NULL) {
-	    free (cg_advances);
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    rv = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    goto BAIL;
 	}
     }
 
@@ -1540,11 +1542,6 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
 				     cg_advances,
 				     num_glyphs);
 
-    if (cg_glyphs != &glyphs_static[0]) {
-	free (cg_glyphs);
-	free (cg_advances);
-    }
-
     if (action == DO_IMAGE) {
 	CGContextConcatCTM (surface->cgContext, surface->sourceImageTransform);
 	if (cairo_surface_get_type(((cairo_surface_pattern_t*)source)->surface) == CAIRO_SURFACE_TYPE_QUARTZ) {
@@ -1557,8 +1554,17 @@ _cairo_quartz_surface_show_glyphs (void *abstract_surface,
 	CGContextDrawShading (surface->cgContext, surface->sourceShading);
     }
 
-    _cairo_quartz_teardown_source (surface, source);
+BAIL:
+    if (cg_advances != &cg_advances_static[0]) {
+	free (cg_advances);
+    }
 
+    if (cg_glyphs != &glyphs_static[0]) {
+	free (cg_glyphs);
+    }
+
+    _cairo_quartz_teardown_source (surface, source);
+    
     CGContextRestoreGState (surface->cgContext);
 
     return rv;
commit 7ad34c1bdc6417ca0e2e1075b67ca09c5318db75
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Mon Nov 12 23:52:52 2007 +0000

    [quartz] fix for cairo_reset_clip()

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 508b8a3..126a291 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1673,6 +1673,9 @@ _cairo_quartz_surface_intersect_clip_path (void *abstract_surface,
 	CGContextBeginPath (surface->cgContext);
 	stroke.cgContext = surface->cgContext;
 	stroke.ctm_inverse = NULL;
+
+	/* path must not be empty. */
+	CGContextMoveToPoint (surface->cgContext, 0, 0);	    
 	status = _cairo_quartz_cairo_path_to_quartz_context (path, &stroke);
 	if (status)
 	    return status;
commit 717ccbcf0c12fcfa840396378812919c9e151d57
Author: Brian Ewins <Brian.Ewins at gmail.com>
Date:   Mon Nov 12 23:51:39 2007 +0000

    Revert "[quartz] handle 0x0 surfaces."
    
    This reverts commit 2fd50a7897efaed4dabaf75a6ed8828f16c14d36.
    Spoke too soon, quartz doesn't like creating those 0x0
    images; while the tests pass, its putting warnings in the logs.
    Reverting to make a better fix.

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 76073f1..508b8a3 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -1882,7 +1882,7 @@ cairo_quartz_surface_create (cairo_format_t format,
     }
 
     imageData = _cairo_malloc_ab (height, stride);
-    if (!imageData && stride > 0 && height > 0) {
+    if (!imageData) {
 	CGColorSpaceRelease (cgColorspace);
 	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_surface_t*) &_cairo_surface_nil;


More information about the cairo-commit mailing list