2006-07-06 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 6 Jul 2006 12:56:07 +0000 (12:56 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 6 Jul 2006 12:56:07 +0000 (12:56 -0000)
* Image.cs: Ensure we're setting the nativeObject to NULL before
throwing any exception while disposing (and avoid possible double
freeing). Avoid multiple casts in Clone method.
* Pen.cs: Ensure the internal pen's brush is always disposed
correctly. Avoid making a reference to the internal brush.
* SolidBrush.cs: Avoid setting color when cloning the solid brush
as the .ctor(IntPtr) always does this job.

svn path=/trunk/mcs/; revision=62313

mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Image.cs
mcs/class/System.Drawing/System.Drawing/Pen.cs
mcs/class/System.Drawing/System.Drawing/SolidBrush.cs

index 8e1195a6d962b087cd3a4743043fdd90cd9a7875..2b84d82c7f668295313f15b7d45d6874a258c8ed 100644 (file)
@@ -1,3 +1,13 @@
+2006-07-06  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * Image.cs: Ensure we're setting the nativeObject to NULL before 
+       throwing any exception while disposing (and avoid possible double
+       freeing). Avoid multiple casts in Clone method.
+       * Pen.cs: Ensure the internal pen's brush is always disposed 
+       correctly. Avoid making a reference to the internal brush.
+       * SolidBrush.cs: Avoid setting color when cloning the solid brush
+       as the .ctor(IntPtr) always does this job.
+
 2006-07-04  Sebastien Pouliot  <sebastien@ximian.com>
 
        * Image.cs: Made GetThumbnailImage throw OutOfMemoryException when
index 5a9a053ebb7b315cbb74a3e71a8bf856045c4e37..a2371aa8159395eaee69506ada4912ab9dfcec83 100644 (file)
@@ -758,38 +758,28 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                Dispose (false);
        }
 
-       private void DisposeResources ()
-       {
-               Status status = GDIPlus.GdipDisposeImage (nativeObject);
-               GDIPlus.CheckStatus (status);           
-       }
-       
        protected virtual void Dispose (bool disposing)
        {
                if (nativeObject != IntPtr.Zero){
-                       DisposeResources ();
+                       Status status = GDIPlus.GdipDisposeImage (nativeObject);
+                       // set nativeObject to null before throwing an exception
                        nativeObject = IntPtr.Zero;
+                       GDIPlus.CheckStatus (status);           
                }
        }
        
-       public object Clone()
-       {                               
+       public object Clone ()
+       {
+               Bitmap b = (this as Bitmap);
+               if (b == null)
+                       throw new NotImplementedException ("This Image instance isn't a Bitmap instance."); 
 
                IntPtr newimage = IntPtr.Zero;
-               
-               if (!(this is Bitmap)) 
-                       throw new NotImplementedException (); 
-               
                Status status = GDIPlus.GdipCloneImage (NativeObject, out newimage);                    
                GDIPlus.CheckStatus (status);                   
 
-               if (this is Bitmap){
-                       return new Bitmap (newimage);
-               }
-               
-               throw new NotImplementedException ();           
+               return new Bitmap (newimage);
        }
-
 }
 
 }
index ac572147d0a0cae872dae1e0b2f4d645d9c24980..40df1b7e7e68af4d0345276241696f5fce51df93 100644 (file)
@@ -180,7 +180,14 @@ namespace System.Drawing
                                        color = value;
                                        Status status = GDIPlus.GdipSetPenColor (nativeObject, value.ToArgb ());
                                        GDIPlus.CheckStatus (status);
+
+                                       /* if required clear existing brush */
+                                       if (must_dispose_brush && (brush != null)) {
+                                               brush.Dispose ();
+                                       }
                                        brush = new SolidBrush (color);
+                                       must_dispose_brush = true;
+
                                        status = GDIPlus.GdipSetPenBrushFill (nativeObject, brush.nativeObject);
                                        GDIPlus.CheckStatus (status);
                                } else
@@ -471,7 +478,7 @@ namespace System.Drawing
                         Status status = GDIPlus.GdipClonePen (nativeObject, out ptr);
                        GDIPlus.CheckStatus (status);
                         Pen p = new Pen (ptr);
-                       p.brush = brush;
+                       p.brush = null; // don't reference! managed brush will be re-created on demand
                        p.color = color;
                        p.startCap = startCap;
                        p.endCap = endCap;
@@ -493,6 +500,7 @@ namespace System.Drawing
 
                        if (must_dispose_brush && (brush != null)) {
                                brush.Dispose ();
+                               brush = null;
                        }
                        if (nativeObject != IntPtr.Zero) {
                                Status status = GDIPlus.GdipDeletePen (nativeObject);
index fbe2a763ecba64208c7eb478db466fb72421d9c5..4e2f5fa58bc8f91113a69cc318017a6220d794ad 100644 (file)
@@ -78,11 +78,7 @@ namespace System.Drawing
                        Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
                        GDIPlus.CheckStatus (status);
        
-                       SolidBrush clone = new SolidBrush (clonePtr);
-                       clone.color = color;
-                       
-                       return clone;
-                       
+                       return new SolidBrush (clonePtr);
                }
                
                protected override void Dispose (bool disposing)