From 80c19b7cac52a57fd04966169c657400aeee3de8 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 27 Feb 2013 00:21:02 +0000 Subject: Make sure we dispose of WebResponse, StreamReader and Stream in various places where we were not already. --- .../Hypergrid/UserAgentServiceConnector.cs | 69 +++++++++++----------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs') diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs index 2f263ae..47d0cce 100644 --- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs @@ -171,41 +171,45 @@ namespace OpenSim.Services.Connectors.Hypergrid // Let's wait for the response //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); - WebResponse webResponse = null; - StreamReader sr = null; try { - webResponse = AgentCreateRequest.GetResponse(); - if (webResponse == null) + using (WebResponse webResponse = AgentCreateRequest.GetResponse()) { - m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post"); - } - else - { - - sr = new StreamReader(webResponse.GetResponseStream()); - string response = sr.ReadToEnd().Trim(); - m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); - - if (!String.IsNullOrEmpty(response)) + if (webResponse == null) { - try - { - // we assume we got an OSDMap back - OSDMap r = Util.GetOSDMap(response); - bool success = r["success"].AsBoolean(); - reason = r["reason"].AsString(); - return success; - } - catch (NullReferenceException e) + m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post"); + } + else + { + using (Stream s = webResponse.GetResponseStream()) { - m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); - - // check for old style response - if (response.ToLower().StartsWith("true")) - return true; - - return false; + using (StreamReader sr = new StreamReader(s)) + { + string response = sr.ReadToEnd().Trim(); + m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); + + if (!String.IsNullOrEmpty(response)) + { + try + { + // we assume we got an OSDMap back + OSDMap r = Util.GetOSDMap(response); + bool success = r["success"].AsBoolean(); + reason = r["reason"].AsString(); + return success; + } + catch (NullReferenceException e) + { + m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); + + // check for old style response + if (response.ToLower().StartsWith("true")) + return true; + + return false; + } + } + } } } } @@ -216,11 +220,6 @@ namespace OpenSim.Services.Connectors.Hypergrid reason = "Destination did not reply"; return false; } - finally - { - if (sr != null) - sr.Close(); - } return true; -- cgit v1.1