Author: spouliot
Date: 2006-06-29 16:03:59 -0400 (Thu, 29 Jun 2006)
New Revision: 62146

Modified:
   trunk/libgdiplus/src/ChangeLog
   trunk/libgdiplus/src/region.c
Log:
2006-06-29  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * region.c: Report OutOfMemory condition in GdipCloneRegion. Ensure 
        all memory is freed from the tree used in GdipCombineRegion* functions
        and avoid some memory alloc/free when possible.



Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog      2006-06-29 18:18:46 UTC (rev 62145)
+++ trunk/libgdiplus/src/ChangeLog      2006-06-29 20:03:59 UTC (rev 62146)
@@ -1,3 +1,9 @@
+2006-06-29  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * region.c: Report OutOfMemory condition in GdipCloneRegion. Ensure 
+       all memory is freed from the tree used in GdipCombineRegion* functions
+       and avoid some memory alloc/free when possible.
+
 2006-06-28  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * font.c: Make sure GdipGetLogFont[A|W] always initialize the LOGFONT

Modified: trunk/libgdiplus/src/region.c
===================================================================
--- trunk/libgdiplus/src/region.c       2006-06-29 18:18:46 UTC (rev 62145)
+++ trunk/libgdiplus/src/region.c       2006-06-29 20:03:59 UTC (rev 62146)
@@ -459,10 +459,12 @@
         if (!region || !cloneRegion)
                 return InvalidParameter;
 
-        result = (GpRegion *) GdipAlloc (sizeof (GpRegion));
+       result = (GpRegion *) GdipAlloc (sizeof (GpRegion));
+       if (!result)
+               return OutOfMemory;
+
        gdip_copy_region (region, result);
-        *cloneRegion = result;
-
+       *cloneRegion = result;
         return Ok;
 }
 
@@ -995,7 +997,6 @@
 GdipCombineRegionPath (GpRegion *region, GpPath *path, CombineMode combineMode)
 {
        GpRegionBitmap *path_bitmap, *result;
-       GpPathTree* tmp;
 
        if (!region || !path)
                return InvalidParameter;
@@ -1065,21 +1066,22 @@
        region->bitmap = result;
 
        /* add a copy of path into region1 tree */
-       tmp = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
-       tmp->mode = combineMode;
-       tmp->path = NULL;
-       tmp->branch1 = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
-       tmp->branch2 = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
-
        if (region->tree->path) {
-               tmp->branch1->path = region->tree->path;
+               /* move the existing path into a new tree (branch1) ... */
+               region->tree->branch1 = (GpPathTree*) GdipAlloc (sizeof 
(GpPathTree));
+               region->tree->branch1->path = region->tree->path;
+               region->tree->branch2 = (GpPathTree*) GdipAlloc (sizeof 
(GpPathTree));
        } else {
-               gdip_region_copy_tree (region->tree, tmp->branch1);
+               /* move the current base tree into branch1 of a new tree ... */
+               GpPathTree* tmp = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
+               tmp->branch1 = region->tree;
+               tmp->branch2 = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
+               region->tree = tmp;
        }
-
-       GdipClonePath (path, &tmp->branch2->path);
-
-       region->tree = tmp;
+       /* ... and clone the specified path into branch2 */
+       region->tree->mode = combineMode;
+       region->tree->path = NULL;
+       GdipClonePath (path, &region->tree->branch2->path);
        return Ok;
 }
 
@@ -1102,27 +1104,28 @@
        gdip_region_bitmap_free (region1->bitmap);
        region1->bitmap = result;
 
-       /* add a copy of region2 tree into region1 tree */
-       tmp = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
-       tmp->mode = combineMode;
-       tmp->path = NULL;
-       tmp->branch1 = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
-       tmp->branch2 = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
-
+       /* re-structure region1 to allow adding a copy of region2 inside it */
        if (region1->tree->path) {
-               tmp->branch1->path = region1->tree->path;
+               region1->tree->branch1 = (GpPathTree*) GdipAlloc (sizeof 
(GpPathTree));
+               region1->tree->branch1->path = region1->tree->path;
+               region1->tree->branch2 = (GpPathTree*) GdipAlloc (sizeof 
(GpPathTree));
        } else {
-               gdip_region_copy_tree (region1->tree, tmp->branch1);
+               /* move the current base tree into branch1 of a new tree ... */
+               GpPathTree* tmp = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
+               tmp->branch1 = region1->tree;
+               tmp->branch2 = (GpPathTree*) GdipAlloc (sizeof (GpPathTree));
+               region1->tree = tmp;
        }
 
+       region1->tree->mode = combineMode;
+       region1->tree->path = NULL;
+
+       /* add a copy of region2 tree into region1 tree */
        if (region2->tree->path) {
-               GdipClonePath (region2->tree->path, &tmp->branch2->path);
+               GdipClonePath (region2->tree->path, 
&region1->tree->branch2->path);
        } else {
-               gdip_region_copy_tree (region2->tree, tmp->branch2);
+               gdip_region_copy_tree (region2->tree, region1->tree->branch2);
        }
-
-       GdipFree (region1->tree);
-       region1->tree = tmp;
        return Ok;
 }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to