[memlk] don't try to allocate new data for 0-rectangle regions
authorVladimir Vukicevic <vladimir@pobox.com>
Mon, 10 Sep 2007 22:20:44 +0000 (15:20 -0700)
committerVladimir Vukicevic <vladimir@pobox.com>
Mon, 10 Sep 2007 22:20:44 +0000 (15:20 -0700)
pixman/pixman-region.c

index fff49e7..ac23806 100644 (file)
@@ -2518,6 +2518,8 @@ pixman_region_init_rects (pixman_region16_t *region,
 {
     int overlap;
 
+    /* if it's 1, then we just want to set the extents, so call
+     * the existing method. */
     if (count == 1) {
        pixman_region_init_rect(region,
                                boxes[0].x1,
@@ -2528,6 +2530,15 @@ pixman_region_init_rects (pixman_region16_t *region,
     }
 
     pixman_region_init(region);
+
+    /* if it's 0, don't call pixman_rect_alloc -- 0 rectangles is
+     * a special case, and causing pixman_rect_alloc would cause
+     * us to leak memory (because the 0-rect case should be the
+     * static pixman_region_emptyData data).
+     */
+    if (count == 0)
+        return TRUE;
+
     if (!pixman_rect_alloc(region, count))
        return FALSE;