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. --- OpenSim/Framework/WebUtil.cs | 61 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'OpenSim/Framework/WebUtil.cs') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 5c34cf4..701fbb0 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -228,8 +228,8 @@ namespace OpenSim.Framework errorMessage = we.Message; if (we.Status == WebExceptionStatus.ProtocolError) { - HttpWebResponse webResponse = (HttpWebResponse)we.Response; - errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription); + using (HttpWebResponse webResponse = (HttpWebResponse)we.Response) + errorMessage = String.Format("[{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription); } } catch (Exception ex) @@ -387,8 +387,8 @@ namespace OpenSim.Framework errorMessage = we.Message; if (we.Status == WebExceptionStatus.ProtocolError) { - HttpWebResponse webResponse = (HttpWebResponse)we.Response; - errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription); + using (HttpWebResponse webResponse = (HttpWebResponse)we.Response) + errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription); } } catch (Exception ex) @@ -834,15 +834,16 @@ namespace OpenSim.Framework { if (e.Response is HttpWebResponse) { - HttpWebResponse httpResponse = (HttpWebResponse)e.Response; - - if (httpResponse.StatusCode != HttpStatusCode.NotFound) - { - // We don't appear to be handling any other status codes, so log these feailures to that - // people don't spend unnecessary hours hunting phantom bugs. - m_log.DebugFormat( - "[ASYNC REQUEST]: Request {0} {1} failed with unexpected status code {2}", - verb, requestUrl, httpResponse.StatusCode); + using (HttpWebResponse httpResponse = (HttpWebResponse)e.Response) + { + if (httpResponse.StatusCode != HttpStatusCode.NotFound) + { + // We don't appear to be handling any other status codes, so log these feailures to that + // people don't spend unnecessary hours hunting phantom bugs. + m_log.DebugFormat( + "[ASYNC REQUEST]: Request {0} {1} failed with unexpected status code {2}", + verb, requestUrl, httpResponse.StatusCode); + } } } } @@ -983,11 +984,9 @@ namespace OpenSim.Framework Stream respStream = null; try { - respStream = resp.GetResponseStream(); - using (StreamReader reader = new StreamReader(respStream)) - { - respstring = reader.ReadToEnd(); - } + using (respStream = resp.GetResponseStream()) + using (StreamReader reader = new StreamReader(respStream)) + respstring = reader.ReadToEnd(); } catch (Exception e) { @@ -1127,10 +1126,11 @@ namespace OpenSim.Framework { if (resp.ContentLength != 0) { - Stream respStream = resp.GetResponseStream(); - XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); - deserial = (TResponse)deserializer.Deserialize(respStream); - respStream.Close(); + using (Stream respStream = resp.GetResponseStream()) + { + XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); + deserial = (TResponse)deserializer.Deserialize(respStream); + } } else { @@ -1142,14 +1142,15 @@ namespace OpenSim.Framework } catch (WebException e) { - HttpWebResponse hwr = (HttpWebResponse)e.Response; - - if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound) - return deserial; - else - m_log.ErrorFormat( - "[SynchronousRestObjectRequester]: WebException for {0} {1} {2}: {3} {4}", - verb, requestUrl, typeof(TResponse).ToString(), e.Message, e.StackTrace); + using (HttpWebResponse hwr = (HttpWebResponse)e.Response) + { + if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound) + return deserial; + else + m_log.ErrorFormat( + "[SynchronousRestObjectRequester]: WebException for {0} {1} {2}: {3} {4}", + verb, requestUrl, typeof(TResponse).ToString(), e.Message, e.StackTrace); + } } catch (System.InvalidOperationException) { -- cgit v1.1