From c7baee16380d67cecf7397258820eb50e2968eca Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 14 Jul 2018 14:05:47 +0100 Subject: [PATCH] add using into a few more places --- OpenSim/Capabilities/LLSD.cs | 20 ++++++++--------- OpenSim/Capabilities/LLSDHelpers.cs | 34 +++++++++++++++-------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/OpenSim/Capabilities/LLSD.cs b/OpenSim/Capabilities/LLSD.cs index 76e439f9e7..342164d9af 100644 --- a/OpenSim/Capabilities/LLSD.cs +++ b/OpenSim/Capabilities/LLSD.cs @@ -107,17 +107,17 @@ namespace OpenSim.Framework.Capabilities /// public static byte[] LLSDSerialize(object obj) { - StringWriter sw = new StringWriter(); - XmlTextWriter writer = new XmlTextWriter(sw); - writer.Formatting = Formatting.None; + using(StringWriter sw = new StringWriter()) + using(XmlTextWriter writer = new XmlTextWriter(sw)) + { + writer.Formatting = Formatting.None; - writer.WriteStartElement(String.Empty, "llsd", String.Empty); - LLSDWriteOne(writer, obj); - writer.WriteEndElement(); - - writer.Close(); - - return Util.UTF8.GetBytes(sw.ToString()); + writer.WriteStartElement(String.Empty, "llsd", String.Empty); + LLSDWriteOne(writer, obj); + writer.WriteEndElement(); + writer.Flush(); + return Util.UTF8.GetBytes(sw.ToString()); + } } /// diff --git a/OpenSim/Capabilities/LLSDHelpers.cs b/OpenSim/Capabilities/LLSDHelpers.cs index 4a7c6a54c9..e54618d3b5 100644 --- a/OpenSim/Capabilities/LLSDHelpers.cs +++ b/OpenSim/Capabilities/LLSDHelpers.cs @@ -41,30 +41,32 @@ namespace OpenSim.Framework.Capabilities public static string SerialiseLLSDReply(object obj) { - StringWriter sw = new StringWriter(); - XmlTextWriter writer = new XmlTextWriter(sw); - writer.Formatting = Formatting.None; - writer.WriteStartElement(String.Empty, "llsd", String.Empty); - SerializeOSDType(writer, obj); - writer.WriteEndElement(); - writer.Close(); - + using(StringWriter sw = new StringWriter()) + using(XmlTextWriter writer = new XmlTextWriter(sw)) + { + writer.Formatting = Formatting.None; + writer.WriteStartElement(String.Empty, "llsd", String.Empty); + SerializeOSDType(writer, obj); + writer.WriteEndElement(); + writer.Flush(); //m_log.DebugFormat("[LLSD Helpers]: Generated serialized LLSD reply {0}", sw.ToString()); - return sw.ToString(); + return sw.ToString(); + } } public static string SerialiseLLSDReplyNoHeader(object obj) { - StringWriter sw = new StringWriter(); - XmlTextWriter writer = new XmlTextWriter(sw); - writer.Formatting = Formatting.None; - SerializeOSDType(writer, obj); - writer.Close(); - + using(StringWriter sw = new StringWriter()) + using(XmlTextWriter writer = new XmlTextWriter(sw)) + { + writer.Formatting = Formatting.None; + SerializeOSDType(writer, obj); + writer.Flush(); //m_log.DebugFormat("[LLSD Helpers]: Generated serialized LLSD reply {0}", sw.ToString()); - return sw.ToString(); + return sw.ToString(); + } } private static void SerializeOSDType(XmlTextWriter writer, object obj)