[cairo-commit] cairo/src cairo_pattern.c,1.20,1.21

Carl Worth commit at pdx.freedesktop.org
Thu Feb 24 14:06:05 PST 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv30979/src

Modified Files:
	cairo_pattern.c 
Log Message:

        * src/cairo_pattern.c (cairo_pattern_add_color_stop): Fix memory
        leak when realloc fails due to out-of-memory.


Index: cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_pattern.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- cairo_pattern.c	21 Feb 2005 16:22:47 -0000	1.20
+++ cairo_pattern.c	24 Feb 2005 22:06:03 -0000	1.21
@@ -215,7 +215,7 @@
 			      double red, double green, double blue,
 			      double alpha)
 {
-    cairo_color_stop_t *stop;
+    cairo_color_stop_t *stop, *new_stops;
     int i;
 
     _cairo_restrict_value (&offset, 0.0, 1.0);
@@ -224,13 +224,13 @@
     _cairo_restrict_value (&blue, 0.0, 1.0);
 
     pattern->n_stops++;
-    pattern->stops = realloc (pattern->stops,
-			      sizeof (cairo_color_stop_t) * pattern->n_stops);
-    if (pattern->stops == NULL) {
-	pattern->n_stops = 0;
-    
+    new_stops = realloc (pattern->stops,
+			 sizeof (cairo_color_stop_t) * pattern->n_stops);
+    if (new_stops == NULL) {
+	pattern->n_stops--;
 	return CAIRO_STATUS_NO_MEMORY;
     }
+    pattern->stops = new_stops;
 
     stop = &pattern->stops[pattern->n_stops - 1];
 




More information about the cairo-commit mailing list