From c8a1d7e5a74161d51841d5abbe9b76a7da51c872 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 22 Aug 2016 03:55:01 +0100 Subject: [PATCH] workaround potencial memory leaks --- .../World/Terrain/FileLoaders/BMP.cs | 10 ++++------ .../World/Terrain/FileLoaders/GIF.cs | 10 ++++------ .../FileLoaders/GenericSystemDrawing.cs | 12 +++++------ .../World/Terrain/FileLoaders/JPEG.cs | 10 ++++------ .../World/Terrain/FileLoaders/PNG.cs | 10 ++++------ .../World/Terrain/FileLoaders/TIFF.cs | 10 ++++------ .../PhysicsModules/ubOdeMeshing/SculptMap.cs | 20 +++++++------------ 7 files changed, 32 insertions(+), 50 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs index 8b95a339ff..ec2d085878 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs @@ -47,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public override void SaveFile(string filename, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(filename, ImageFormat.Bmp); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(filename,ImageFormat.Bmp); } /// @@ -59,9 +58,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public override void SaveStream(Stream stream, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(stream, ImageFormat.Bmp); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(stream,ImageFormat.Bmp); } /// diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs index 79cc50b386..384370890d 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs @@ -36,9 +36,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders { public override void SaveFile(string filename, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(filename, ImageFormat.Gif); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(filename,ImageFormat.Gif); } /// @@ -48,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public override void SaveStream(Stream stream, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(stream, ImageFormat.Gif); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(stream,ImageFormat.Gif); } public override string ToString() diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs index e8c719a700..1e67f72276 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs @@ -59,7 +59,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// A terrain channel generated from the image. public virtual ITerrainChannel LoadFile(string filename) { - using (Bitmap b = new Bitmap(filename)) + using(Bitmap b = new Bitmap(filename)) return LoadBitmap(b); } @@ -111,9 +111,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public virtual void SaveFile(string filename, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(filename, ImageFormat.Png); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(filename,ImageFormat.Png); } /// @@ -123,9 +122,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public virtual void SaveStream(Stream stream, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(stream, ImageFormat.Png); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(stream,ImageFormat.Png); } public virtual void SaveFile(ITerrainChannel m_channel, string filename, diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs index 9cc767a43e..36c2bbf3fa 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs @@ -59,9 +59,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders public void SaveFile(string filename, ITerrainChannel map) { - Bitmap colours = CreateBitmapFromMap(map); - - colours.Save(filename, ImageFormat.Jpeg); + using(Bitmap colours = CreateBitmapFromMap(map)) + colours.Save(filename,ImageFormat.Jpeg); } /// @@ -71,9 +70,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public void SaveStream(Stream stream, ITerrainChannel map) { - Bitmap colours = CreateBitmapFromMap(map); - - colours.Save(stream, ImageFormat.Jpeg); + using(Bitmap colours = CreateBitmapFromMap(map)) + colours.Save(stream,ImageFormat.Jpeg); } public virtual void SaveFile(ITerrainChannel m_channel, string filename, diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs index c5c12ae6cf..8ea8e9d61d 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs @@ -36,9 +36,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders { public override void SaveFile(string filename, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(filename, ImageFormat.Png); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(filename,ImageFormat.Png); } /// @@ -48,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public override void SaveStream(Stream stream, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(stream, ImageFormat.Png); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(stream,ImageFormat.Png); } public override string ToString() diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs index b416b82a17..d103a6fd1e 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs @@ -36,9 +36,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders { public override void SaveFile(string filename, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(filename, ImageFormat.Tiff); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(filename,ImageFormat.Tiff); } /// @@ -48,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders /// The terrain channel being saved public override void SaveStream(Stream stream, ITerrainChannel map) { - Bitmap colours = CreateGrayscaleBitmapFromMap(map); - - colours.Save(stream, ImageFormat.Tiff); + using(Bitmap colours = CreateGrayscaleBitmapFromMap(map)) + colours.Save(stream,ImageFormat.Tiff); } public override string ToString() diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs index 1c75db67c5..2ca2af7bbb 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs @@ -57,7 +57,7 @@ namespace PrimMesher int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image bool needsScaling = false; - bool smallMap = false; + bool smallMap = false; width = bmW; height = bmH; @@ -69,16 +69,8 @@ namespace PrimMesher needsScaling = true; } - try - { - if (needsScaling) - bm = ScaleImage(bm, width, height); - } - - catch (Exception e) - { - throw new Exception("Exception in ScaleImage(): e: " + e.ToString()); - } + if (needsScaling) + bm = ScaleImage(bm, width, height); if (width * height > numLodPixels) { @@ -129,11 +121,15 @@ namespace PrimMesher } catch (Exception e) { + if (needsScaling) + bm.Dispose(); throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString()); } width++; height++; + if(needsScaling) + bm.Dispose(); } public List> ToRows(bool mirror) @@ -168,11 +164,9 @@ namespace PrimMesher private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight) { - Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb); Color c; - // will let last step to be eventually diferent, as seems to be in sl