aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/CodeTools
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-12-03 18:58:55 +0000
committerJustin Clark-Casey (justincc)2014-12-03 20:31:09 +0000
commit72d1d96c5c9b8f9f31e21ef4a3d542a27fc6c3f8 (patch)
tree90a7eebc4397f2f5abca4c545f7de96f30cabb78 /OpenSim/Region/ScriptEngine/Shared/CodeTools
parentFix typo in ini (diff)
downloadopensim-SC_OLD-72d1d96c5c9b8f9f31e21ef4a3d542a27fc6c3f8.zip
opensim-SC_OLD-72d1d96c5c9b8f9f31e21ef4a3d542a27fc6c3f8.tar.gz
opensim-SC_OLD-72d1d96c5c9b8f9f31e21ef4a3d542a27fc6c3f8.tar.bz2
opensim-SC_OLD-72d1d96c5c9b8f9f31e21ef4a3d542a27fc6c3f8.tar.xz
Always close script linemap file after reading and always dispose of other streams in the script engine even if exceptions are thrown.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs49
1 files changed, 24 insertions, 25 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index 9379f8f..de5f92d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -663,9 +663,8 @@ namespace SecondLife
663 663
664 try 664 try
665 { 665 {
666 FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read); 666 using (FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read))
667 fs.Read(data, 0, data.Length); 667 fs.Read(data, 0, data.Length);
668 fs.Close();
669 } 668 }
670 catch (Exception) 669 catch (Exception)
671 { 670 {
@@ -680,9 +679,8 @@ namespace SecondLife
680 679
681 Byte[] buf = Encoding.ASCII.GetBytes(filetext); 680 Byte[] buf = Encoding.ASCII.GetBytes(filetext);
682 681
683 FileStream sfs = File.Create(assembly + ".text"); 682 using (FileStream sfs = File.Create(assembly + ".text"))
684 sfs.Write(buf, 0, buf.Length); 683 sfs.Write(buf, 0, buf.Length);
685 sfs.Close();
686 684
687 return assembly; 685 return assembly;
688 } 686 }
@@ -775,7 +773,6 @@ namespace SecondLife
775 return message; 773 return message;
776 } 774 }
777 775
778
779 private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) 776 private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
780 { 777 {
781 string mapstring = String.Empty; 778 string mapstring = String.Empty;
@@ -787,40 +784,42 @@ namespace SecondLife
787 } 784 }
788 785
789 Byte[] mapbytes = Encoding.ASCII.GetBytes(mapstring); 786 Byte[] mapbytes = Encoding.ASCII.GetBytes(mapstring);
790 FileStream mfs = File.Create(filename);
791 mfs.Write(mapbytes, 0, mapbytes.Length);
792 mfs.Close();
793 }
794 787
788 using (FileStream mfs = File.Create(filename))
789 mfs.Write(mapbytes, 0, mapbytes.Length);
790 }
795 791
796 private static Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ReadMapFile(string filename) 792 private static Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ReadMapFile(string filename)
797 { 793 {
798 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap; 794 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap;
799 try 795 try
800 { 796 {
801 StreamReader r = File.OpenText(filename); 797 using (StreamReader r = File.OpenText(filename))
802 linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
803
804 string line;
805 while ((line = r.ReadLine()) != null)
806 { 798 {
807 String[] parts = line.Split(new Char[] { ',' }); 799 linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
808 int kk = System.Convert.ToInt32(parts[0]);
809 int kv = System.Convert.ToInt32(parts[1]);
810 int vk = System.Convert.ToInt32(parts[2]);
811 int vv = System.Convert.ToInt32(parts[3]);
812 800
813 KeyValuePair<int, int> k = new KeyValuePair<int, int>(kk, kv); 801 string line;
814 KeyValuePair<int, int> v = new KeyValuePair<int, int>(vk, vv); 802 while ((line = r.ReadLine()) != null)
803 {
804 String[] parts = line.Split(new Char[] { ',' });
805 int kk = System.Convert.ToInt32(parts[0]);
806 int kv = System.Convert.ToInt32(parts[1]);
807 int vk = System.Convert.ToInt32(parts[2]);
808 int vv = System.Convert.ToInt32(parts[3]);
809
810 KeyValuePair<int, int> k = new KeyValuePair<int, int>(kk, kv);
811 KeyValuePair<int, int> v = new KeyValuePair<int, int>(vk, vv);
815 812
816 linemap[k] = v; 813 linemap[k] = v;
814 }
817 } 815 }
818 } 816 }
819 catch 817 catch
820 { 818 {
821 linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>(); 819 linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
822 } 820 }
821
823 return linemap; 822 return linemap;
824 } 823 }
825 } 824 }
826} 825} \ No newline at end of file