Always close script linemap file after reading and always dispose of other streams in the script engine even if exceptions are thrown.

mb-throttle-test
Justin Clark-Casey (justincc) 2014-12-03 18:58:55 +00:00
parent caa7b1e6a1
commit 72d1d96c5c
2 changed files with 29 additions and 29 deletions

View File

@ -663,9 +663,8 @@ namespace SecondLife
try
{
FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read);
using (FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read))
fs.Read(data, 0, data.Length);
fs.Close();
}
catch (Exception)
{
@ -680,9 +679,8 @@ namespace SecondLife
Byte[] buf = Encoding.ASCII.GetBytes(filetext);
FileStream sfs = File.Create(assembly + ".text");
using (FileStream sfs = File.Create(assembly + ".text"))
sfs.Write(buf, 0, buf.Length);
sfs.Close();
return assembly;
}
@ -775,7 +773,6 @@ namespace SecondLife
return message;
}
private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
{
string mapstring = String.Empty;
@ -787,18 +784,18 @@ namespace SecondLife
}
Byte[] mapbytes = Encoding.ASCII.GetBytes(mapstring);
FileStream mfs = File.Create(filename);
mfs.Write(mapbytes, 0, mapbytes.Length);
mfs.Close();
}
using (FileStream mfs = File.Create(filename))
mfs.Write(mapbytes, 0, mapbytes.Length);
}
private static Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ReadMapFile(string filename)
{
Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap;
try
{
StreamReader r = File.OpenText(filename);
using (StreamReader r = File.OpenText(filename))
{
linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
string line;
@ -816,10 +813,12 @@ namespace SecondLife
linemap[k] = v;
}
}
}
catch
{
linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
}
return linemap;
}
}

View File

@ -1065,10 +1065,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
try
{
FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state"));
using (FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state")))
{
Byte[] buf = Util.UTF8NoBomEncoding.GetBytes(xml);
fs.Write(buf, 0, buf.Length);
fs.Close();
}
}
catch(Exception)
{