From cba64ebc79eaec9cd432d90b8cc48e22272d31f0 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 20 Apr 2012 03:46:09 +0100
Subject: Explicitly dispose of bitmaps opened from files in
GenericSystemDrawing and JPEG.cs
---
.../Terrain/FileLoaders/GenericSystemDrawing.cs | 28 ++++++++++++++--------
.../CoreModules/World/Terrain/FileLoaders/JPEG.cs | 21 +++++++++-------
2 files changed, 31 insertions(+), 18 deletions(-)
(limited to 'OpenSim/Region/CoreModules/World/Terrain')
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index cd46276..3921bf9 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -59,7 +59,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// A terrain channel generated from the image.
public virtual ITerrainChannel LoadFile(string filename)
{
- return LoadBitmap(new Bitmap(filename));
+ using (Bitmap b = new Bitmap(filename))
+ return LoadBitmap(b);
}
public virtual ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int w, int h)
@@ -75,13 +76,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
retval[x, y] = bitmap.GetPixel(offsetX * retval.Width + x, (bitmap.Height - (retval.Height * (offsetY + 1))) + retval.Height - y - 1).GetBrightness() * 128;
}
}
+
return retval;
}
}
public virtual ITerrainChannel LoadStream(Stream stream)
{
- return LoadBitmap(new Bitmap(stream));
+ using (Bitmap b = new Bitmap(stream))
+ return LoadBitmap(b);
}
protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap)
@@ -227,16 +230,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// A System.Drawing.Bitmap containing a coloured image
protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{
- Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
-
- int pallete = gradientmapLd.Height;
-
- Bitmap bmp = new Bitmap(map.Width, map.Height);
- Color[] colours = new Color[pallete];
+ int pallete;
+ Bitmap bmp;
+ Color[] colours;
- for (int i = 0; i < pallete; i++)
+ using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
{
- colours[i] = gradientmapLd.GetPixel(0, i);
+ pallete = gradientmapLd.Height;
+
+ bmp = new Bitmap(map.Width, map.Height);
+ colours = new Color[pallete];
+
+ for (int i = 0; i < pallete; i++)
+ {
+ colours[i] = gradientmapLd.GetPixel(0, i);
+ }
}
for (int y = 0; y < map.Height; y++)
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
index 699d67a..9cc767a 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
@@ -99,16 +99,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
private static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{
- Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
+ int pallete;
+ Bitmap bmp;
+ Color[] colours;
- int pallete = gradientmapLd.Height;
-
- Bitmap bmp = new Bitmap(map.Width, map.Height);
- Color[] colours = new Color[pallete];
-
- for (int i = 0; i < pallete; i++)
+ using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
{
- colours[i] = gradientmapLd.GetPixel(0, i);
+ pallete = gradientmapLd.Height;
+
+ bmp = new Bitmap(map.Width, map.Height);
+ colours = new Color[pallete];
+
+ for (int i = 0; i < pallete; i++)
+ {
+ colours[i] = gradientmapLd.GetPixel(0, i);
+ }
}
for (int y = 0; y < map.Height; y++)
--
cgit v1.1