From 99ac770abbe3a95887c4b10c82f3985aa878eeef Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Sun, 1 Jun 2014 17:39:11 +0300 Subject: Close streams immediately when we finish using them --- .../Servers/HttpServer/RestObjectPoster.cs | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs') diff --git a/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs b/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs index 48ced19..afe052f 100644 --- a/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs +++ b/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs @@ -52,23 +52,25 @@ namespace OpenSim.Framework.Servers.HttpServer request.Method = verb; request.ContentType = "text/xml"; - MemoryStream buffer = new MemoryStream(); + using (MemoryStream buffer = new MemoryStream()) + { + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Encoding.UTF8; - XmlWriterSettings settings = new XmlWriterSettings(); - settings.Encoding = Encoding.UTF8; + using (XmlWriter writer = XmlWriter.Create(buffer, settings)) + { + XmlSerializer serializer = new XmlSerializer(type); + serializer.Serialize(writer, obj); + writer.Flush(); + } - using (XmlWriter writer = XmlWriter.Create(buffer, settings)) - { - XmlSerializer serializer = new XmlSerializer(type); - serializer.Serialize(writer, obj); - writer.Flush(); - } + int length = (int)buffer.Length; + request.ContentLength = length; - int length = (int) buffer.Length; - request.ContentLength = length; + using (Stream requestStream = request.GetRequestStream()) + requestStream.Write(buffer.ToArray(), 0, length); + } - Stream requestStream = request.GetRequestStream(); - requestStream.Write(buffer.ToArray(), 0, length); // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); request.BeginGetResponse(AsyncCallback, request); } -- cgit v1.1