From fb0c8036f025f0211e0205d65aead79eac695060 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 20 Nov 2018 23:07:14 +0000 Subject: Yengine: use using... --- .../Region/ScriptEngine/YEngine/XMRInstCapture.cs | 21 ++++++++++++--------- OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/YEngine') diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs index e90d83b..9bb894d 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCapture.cs @@ -87,10 +87,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine CheckRunLockInvariants(true); // Get copy of script globals and stack in relocateable form. - MemoryStream snapshotStream = new MemoryStream(); - MigrateOutEventHandler(snapshotStream); - Byte[] snapshotBytes = snapshotStream.ToArray(); - snapshotStream.Close(); + Byte[] snapshotBytes; + using (MemoryStream snapshotStream = new MemoryStream()) + { + MigrateOutEventHandler(snapshotStream); + snapshotBytes = snapshotStream.ToArray(); + } + string snapshotString = Convert.ToBase64String(snapshotBytes); XmlElement snapshotN = doc.CreateElement("", "Snapshot", ""); snapshotN.AppendChild(doc.CreateTextNode(snapshotString)); @@ -180,11 +183,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine // scriptStateN represents the contents of the .state file so // write the .state file while we are here. - FileStream fs = File.Create(m_StateFileName); - StreamWriter sw = new StreamWriter(fs); - sw.Write(scriptStateN.OuterXml); - sw.Close(); - fs.Close(); + using(FileStream fs = File.Create(m_StateFileName)) + { + using(StreamWriter sw = new StreamWriter(fs)) + sw.Write(scriptStateN.OuterXml); + } return scriptStateN; } diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs index 8cea9f2..f7c4a7d 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs @@ -190,7 +190,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine // copy scripts or not. byte[] scbytes = System.Text.Encoding.UTF8.GetBytes(m_SourceCode); StringBuilder sb = new StringBuilder((256 + 5) / 6); - ByteArrayToSixbitStr(sb, System.Security.Cryptography.SHA256.Create().ComputeHash(scbytes)); + using (System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create()) + ByteArrayToSixbitStr(sb, sha.ComputeHash(scbytes)); m_ScriptObjCodeKey = sb.ToString(); // But source code can be just a sixbit string itself -- cgit v1.1