Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Bug #1074851] Fix a few memory leaks.

The largest leaks were in the Flood Tool and the Finish Pixels history
item.
  • Loading branch information...
commit fc971db034a0fa1cac4e32a55c726e4b703f24db 1 parent 93f15d9
@cameronwhite cameronwhite authored
View
60 Pinta.Core/Classes/BaseTool.cs
@@ -324,41 +324,39 @@ public void SetCursor (Gdk.Cursor cursor)
shapeX = imgToShapeX - iconBBox.Left;
shapeY = imgToShapeY - iconBBox.Top;
- ImageSurface i = new ImageSurface(Format.ARGB32, iconBBox.Width, iconBBox.Height);
- using (Context g = new Context(i))
- {
- // Don't show shape if shapeWidth less than 3,
- if (shapeWidth > 3)
- {
- int diam = Math.Max (1, shapeWidth - 2);
- Cairo.Rectangle shapeRect = new Cairo.Rectangle(shapeX - halfOfShapeWidth,
- shapeY - halfOfShapeWidth,
- diam,
- diam);
-
- Cairo.Color outerColor = new Cairo.Color (255, 255, 255, 0.5);
- Cairo.Color innerColor = new Cairo.Color (0, 0, 0);
-
- switch (shape)
- {
- case CursorShape.Ellipse:
- g.DrawEllipse(shapeRect, outerColor, 1);
- shapeRect = shapeRect.Inflate (-1, -1);
- g.DrawEllipse(shapeRect, innerColor, 1);
- break;
- case CursorShape.Rectangle:
- g.DrawRectangle(shapeRect, outerColor, 1);
- shapeRect = shapeRect.Inflate (-1, -1);
- g.DrawRectangle(shapeRect, innerColor, 1);
- break;
+ using (ImageSurface i = new ImageSurface (Format.ARGB32, iconBBox.Width, iconBBox.Height)) {
+ using (Context g = new Context (i)) {
+ // Don't show shape if shapeWidth less than 3,
+ if (shapeWidth > 3) {
+ int diam = Math.Max (1, shapeWidth - 2);
+ Cairo.Rectangle shapeRect = new Cairo.Rectangle (shapeX - halfOfShapeWidth,
+ shapeY - halfOfShapeWidth,
+ diam,
+ diam);
+
+ Cairo.Color outerColor = new Cairo.Color (255, 255, 255, 0.5);
+ Cairo.Color innerColor = new Cairo.Color (0, 0, 0);
+
+ switch (shape) {
+ case CursorShape.Ellipse:
+ g.DrawEllipse (shapeRect, outerColor, 1);
+ shapeRect = shapeRect.Inflate (-1, -1);
+ g.DrawEllipse (shapeRect, innerColor, 1);
+ break;
+ case CursorShape.Rectangle:
+ g.DrawRectangle (shapeRect, outerColor, 1);
+ shapeRect = shapeRect.Inflate (-1, -1);
+ g.DrawRectangle (shapeRect, innerColor, 1);
+ break;
+ }
}
+
+ // Draw the image
+ g.DrawPixbuf (img, new Cairo.Point (imgX, imgY));
}
- // Draw the image
- g.DrawPixbuf(img, new Cairo.Point(imgX, imgY));
+ return CairoExtensions.ToPixbuf (i);
}
-
- return CairoExtensions.ToPixbuf(i);
}
#endregion
View
24 Pinta.Core/Extensions/CairoExtensions.cs
@@ -684,21 +684,21 @@ public static bool ContainsPoint (this Cairo.Rectangle r, Cairo.PointD point)
public unsafe static Gdk.Pixbuf ToPixbuf (this Cairo.ImageSurface surfSource)
{
- Cairo.ImageSurface surf = surfSource.Clone ();
- surf.Flush ();
+ using (Cairo.ImageSurface surf = surfSource.Clone ()) {
+ surf.Flush ();
- ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
- int len = surf.Data.Length / 4;
+ ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
+ int len = surf.Data.Length / 4;
- for (int i = 0; i < len; i++) {
- if (dstPtr->A != 0)
- *dstPtr = (ColorBgra.FromBgra (dstPtr->R, dstPtr->G, dstPtr->B, dstPtr->A));
- dstPtr++;
- }
+ for (int i = 0; i < len; i++) {
+ if (dstPtr->A != 0)
+ *dstPtr = (ColorBgra.FromBgra (dstPtr->R, dstPtr->G, dstPtr->B, dstPtr->A));
+ dstPtr++;
+ }
- Gdk.Pixbuf pb = new Gdk.Pixbuf (surf.Data, true, 8, surf.Width, surf.Height, surf.Stride);
- (surf as IDisposable).Dispose ();
- return pb;
+ Gdk.Pixbuf pb = new Gdk.Pixbuf (surf.Data, true, 8, surf.Width, surf.Height, surf.Stride);
+ return pb;
+ }
}
public unsafe static Color GetPixel (this Cairo.ImageSurface surf, int x, int y)
View
2  Pinta.Core/HistoryItems/FinishPixelsHistoryItem.cs
@@ -88,6 +88,8 @@ public override void Dispose ()
{
if (old_surface != null)
(old_surface as IDisposable).Dispose ();
+ if (old_selection_layer != null)
+ old_selection_layer.Dispose ();
}
public void TakeSnapshot ()
View
5 Pinta.Gui.Widgets/Widgets/History/HistoryTreeView.cs
@@ -119,7 +119,10 @@ private void HistoryRenderText (Gtk.TreeViewColumn column, Gtk.CellRenderer cell
private void HistoryRenderIcon (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
BaseHistoryItem item = (BaseHistoryItem)model.GetValue (iter, 0);
- (cell as Gtk.CellRendererPixbuf).Pixbuf = PintaCore.Resources.GetIcon (item.Icon);
+ var pixbuf_cell = cell as Gtk.CellRendererPixbuf;
+ if (pixbuf_cell.Pixbuf != null)
+ pixbuf_cell.Pixbuf.Dispose ();
+ pixbuf_cell.Pixbuf = PintaCore.Resources.GetIcon (item.Icon);
}
private void OnHistoryItemsChanged (object o, EventArgs args)
View
39 Pinta.Tools/Tools/FloodTool.cs
@@ -52,8 +52,6 @@ public abstract class FloodTool : BaseTool
protected ToolBarSlider tolerance_slider;
private bool limitToSelection = true;
- protected IBitVector2D stencil;
-
#region Protected Properties
protected bool IsContinguousMode { get { return (bool)mode_button.SelectedItem.Tag; } }
protected float Tolerance { get { return (float)(tolerance_slider.Slider.Value / 100); } }
@@ -126,25 +124,24 @@ protected override void OnMouseDown (Gtk.DrawingArea canvas, Gtk.ButtonPressEven
}
ImageSurface surface = doc.CurrentUserLayer.Surface;
- ImageSurface stencil_surface = new ImageSurface (Format.Argb32, (int)surface.Width, (int)surface.Height);
-
- IBitVector2D stencilBuffer = new BitVector2DSurfaceAdapter (stencil_surface);
- int tol = (int)(Tolerance * Tolerance * 256);
- Rectangle boundingBox;
-
- if (IsContinguousMode)
- FillStencilFromPoint (surface, stencilBuffer, pos, tol, out boundingBox, currentRegion, limitToSelection);
- else
- FillStencilByColor (surface, stencilBuffer, surface.GetColorBgra (pos.X, pos.Y), tol, out boundingBox, currentRegion, LimitToSelection);
-
- stencil = stencilBuffer;
- OnFillRegionComputed (stencilBuffer);
-
- // If a derived tool is only going to use the stencil,
- // don't waste time building the polygon set
- if (CalculatePolygonSet) {
- Point[][] polygonSet = stencilBuffer.CreatePolygonSet (boundingBox, 0, 0);
- OnFillRegionComputed (polygonSet);
+ using (var stencil_surface = new ImageSurface (Format.Argb32, (int)surface.Width, (int)surface.Height)) {
+ IBitVector2D stencilBuffer = new BitVector2DSurfaceAdapter (stencil_surface);
+ int tol = (int)(Tolerance * Tolerance * 256);
+ Rectangle boundingBox;
+
+ if (IsContinguousMode)
+ FillStencilFromPoint (surface, stencilBuffer, pos, tol, out boundingBox, currentRegion, limitToSelection);
+ else
+ FillStencilByColor (surface, stencilBuffer, surface.GetColorBgra (pos.X, pos.Y), tol, out boundingBox, currentRegion, LimitToSelection);
+
+ OnFillRegionComputed (stencilBuffer);
+
+ // If a derived tool is only going to use the stencil,
+ // don't waste time building the polygon set
+ if (CalculatePolygonSet) {
+ Point[][] polygonSet = stencilBuffer.CreatePolygonSet (boundingBox, 0, 0);
+ OnFillRegionComputed (polygonSet);
+ }
}
}
#endregion
Please sign in to comment.
Something went wrong with that request. Please try again.