[cairo] more quartz cleanup

Josh Aas joshmoz at gmail.com
Thu Aug 18 14:20:29 PDT 2005


Hi,

The attached patch does whitespace cleanup so things line up, and the
file has been detabbed. This makes it easier to read in most text
editors and getting it out of the way now will make future patches
more clear. There is one thing in the patch that is not whitespace
cleanup:

-	/* XXX: I assume we're leaking memory here, but I don't know
-	 * the right call to use to clean up from CGImageCreate. */
-	return CAIRO_STATUS_NO_MEMORY;
+        if (surface->cgImage)
+            CGImageRelease(surface->cgImage);
+        return CAIRO_STATUS_NO_MEMORY;

It looks like if the cgImage gets created, we should just release it
if the cairo_image_surface_create_for_data() call failed. I'm not sure
why Calum didn't just do this before since if he wrote the whole file
then he already knew about CGImageRelease(). We might do more with the
memory mgmt in this function, but this should be good enough for now,
avoiding the biggest leak.

Thanks,
Josh Aas
-------------- next part --------------
Index: cairo-quartz-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-quartz-surface.c,v
retrieving revision 1.19
diff -u -r1.19 cairo-quartz-surface.c
--- cairo-quartz-surface.c	31 Jul 2005 18:03:35 -0000	1.19
+++ cairo-quartz-surface.c	18 Aug 2005 21:07:20 -0000
@@ -74,8 +74,8 @@
 
 static cairo_status_t
 _cairo_quartz_surface_acquire_source_image(void *abstract_surface,
-					   cairo_image_surface_t **image_out,
-					   void **image_extra)
+                                           cairo_image_surface_t **image_out,
+                                           void **image_extra)
 {
     cairo_quartz_surface_t *surface = abstract_surface;
     CGColorSpaceRef colorSpace;
@@ -89,14 +89,12 @@
     // image surface. 
     if (surface->image) {
         cairo_surface_reference(&surface->image->base);
-
-	*image_out = surface->image;
-	return CAIRO_STATUS_SUCCESS;
+        *image_out = surface->image;
+        return CAIRO_STATUS_SUCCESS;
     }
 
     colorSpace = CGColorSpaceCreateDeviceRGB();
 
-
     rowBytes = surface->width * 4;
     imageDataSize = rowBytes * surface->height;
     imageData = malloc(imageDataSize);
@@ -125,9 +123,9 @@
                                             surface->width,
                                             surface->height, rowBytes);
     if (surface->image->base.status) {
-	/* XXX: I assume we're leaking memory here, but I don't know
-	 * the right call to use to clean up from CGImageCreate. */
-	return CAIRO_STATUS_NO_MEMORY;
+        if (surface->cgImage)
+            CGImageRelease(surface->cgImage);
+        return CAIRO_STATUS_NO_MEMORY;
     }
 
     *image_out = surface->image;
@@ -153,7 +151,7 @@
 
     *image_out = surface->image;
     if (image_extra)
-	*image_extra = NULL;
+        *image_extra = NULL;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -176,7 +174,7 @@
 
         CGContextDrawImage(surface->context, rect, surface->cgImage);
 
-	memset(surface->image->data, 0, surface->width * surface->height * 4);
+        memset(surface->image->data, 0, surface->width * surface->height * 4);
     }
 }
 
@@ -189,12 +187,12 @@
 
     serial = _cairo_surface_allocate_clip_serial (&surface->image->base);
     return _cairo_surface_set_clip_region(&surface->image->base,
-					  region, serial);
+                                          region, serial);
 }
 
 static cairo_int_status_t
-_cairo_quartz_surface_get_extents (void *abstract_surface,
-				   cairo_rectangle_t * rectangle)
+_cairo_quartz_surface_get_extents(void *abstract_surface,
+                                  cairo_rectangle_t * rectangle)
 {
     cairo_quartz_surface_t *surface = abstract_surface;
 
@@ -233,7 +231,7 @@
 
     surface = malloc(sizeof(cairo_quartz_surface_t));
     if (surface == NULL) {
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+        _cairo_error (CAIRO_STATUS_NO_MEMORY);
         return (cairo_surface_t*) &_cairo_surface_nil;
     }
 


More information about the cairo mailing list