aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-02-27 00:21:02 +0000
committerJustin Clark-Casey (justincc)2013-02-27 00:21:02 +0000
commit80c19b7cac52a57fd04966169c657400aeee3de8 (patch)
tree32c48c0d00da28ed091d8c6a671d43d1e9ab8bdb /OpenSim/Framework
parentminor: Remove unnecessary very old System.Net reference in OpenSim.Region.Scr... (diff)
downloadopensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.zip
opensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.tar.gz
opensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.tar.bz2
opensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.tar.xz
Make sure we dispose of WebResponse, StreamReader and Stream in various places where we were not already.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs32
-rw-r--r--OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs41
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestSessionService.cs15
-rw-r--r--OpenSim/Framework/WebUtil.cs61
4 files changed, 81 insertions, 68 deletions
diff --git a/OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs b/OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs
index 3dce578..6681c37 100644
--- a/OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs
+++ b/OpenSim/Framework/Configuration/HTTP/HTTPConfiguration.cs
@@ -65,23 +65,27 @@ namespace OpenSim.Framework.Configuration.HTTP
65 byte[] buf = new byte[8192]; 65 byte[] buf = new byte[8192];
66 HttpWebRequest request = 66 HttpWebRequest request =
67 (HttpWebRequest) WebRequest.Create(remoteConfigSettings.baseConfigURL + configFileName); 67 (HttpWebRequest) WebRequest.Create(remoteConfigSettings.baseConfigURL + configFileName);
68 HttpWebResponse response = (HttpWebResponse) request.GetResponse(); 68 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
69
70 Stream resStream = response.GetResponseStream();
71
72 string tempString = null;
73 int count = 0;
74
75 do
76 { 69 {
77 count = resStream.Read(buf, 0, buf.Length); 70 using (Stream resStream = response.GetResponseStream())
78 if (count != 0)
79 { 71 {
80 tempString = Util.UTF8.GetString(buf, 0, count); 72 string tempString = null;
81 sb.Append(tempString); 73 int count = 0;
74
75 do
76 {
77 count = resStream.Read(buf, 0, buf.Length);
78 if (count != 0)
79 {
80 tempString = Util.UTF8.GetString(buf, 0, count);
81 sb.Append(tempString);
82 }
83 }
84 while (count > 0);
85
86 LoadDataFromString(sb.ToString());
82 } 87 }
83 } while (count > 0); 88 }
84 LoadDataFromString(sb.ToString());
85 } 89 }
86 catch (WebException) 90 catch (WebException)
87 { 91 {
diff --git a/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs b/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
index a2f5d9c..05c64fa 100644
--- a/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
+++ b/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
@@ -74,16 +74,26 @@ namespace OpenSim.Framework.RegionLoader.Web
74 74
75 try 75 try
76 { 76 {
77 HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
78 m_log.Debug("[WEBLOADER]: Downloading region information...");
79 StreamReader reader = new StreamReader(webResponse.GetResponseStream());
80 string xmlSource = String.Empty; 77 string xmlSource = String.Empty;
81 string tempStr = reader.ReadLine(); 78
82 while (tempStr != null) 79 using (HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse())
83 { 80 {
84 xmlSource = xmlSource + tempStr; 81 m_log.Debug("[WEBLOADER]: Downloading region information...");
85 tempStr = reader.ReadLine(); 82
83 using (Stream s = webResponse.GetResponseStream())
84 {
85 using (StreamReader reader = new StreamReader(s))
86 {
87 string tempStr = reader.ReadLine();
88 while (tempStr != null)
89 {
90 xmlSource = xmlSource + tempStr;
91 tempStr = reader.ReadLine();
92 }
93 }
94 }
86 } 95 }
96
87 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " + 97 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " +
88 xmlSource.Length); 98 xmlSource.Length);
89 XmlDocument xmlDoc = new XmlDocument(); 99 XmlDocument xmlDoc = new XmlDocument();
@@ -107,17 +117,24 @@ namespace OpenSim.Framework.RegionLoader.Web
107 } 117 }
108 catch (WebException ex) 118 catch (WebException ex)
109 { 119 {
110 if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound) 120 using (HttpWebResponse response = (HttpWebResponse)ex.Response)
111 { 121 {
112 if (!allowRegionless) 122 if (response.StatusCode == HttpStatusCode.NotFound)
123 {
124 if (!allowRegionless)
125 throw ex;
126 }
127 else
128 {
113 throw ex; 129 throw ex;
130 }
114 } 131 }
115 else
116 throw ex;
117 } 132 }
118 133
119 if (regionCount > 0 | allowRegionless) 134 if (regionCount > 0 | allowRegionless)
135 {
120 return regionInfos; 136 return regionInfos;
137 }
121 else 138 else
122 { 139 {
123 m_log.Error("[WEBLOADER]: No region configs were available."); 140 m_log.Error("[WEBLOADER]: No region configs were available.");
@@ -127,4 +144,4 @@ namespace OpenSim.Framework.RegionLoader.Web
127 } 144 }
128 } 145 }
129 } 146 }
130} 147} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
index 19c03a8..edcd134 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
@@ -101,20 +101,11 @@ namespace OpenSim.Framework.Servers.HttpServer
101 using (WebResponse resp = request.GetResponse()) 101 using (WebResponse resp = request.GetResponse())
102 { 102 {
103 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); 103 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
104 Stream respStream = null; 104
105 try 105 using (Stream respStream = resp.GetResponseStream())
106 {
107 respStream = resp.GetResponseStream();
108 deserial = (TResponse)deserializer.Deserialize(respStream); 106 deserial = (TResponse)deserializer.Deserialize(respStream);
109 }
110 catch { }
111 finally
112 {
113 if (respStream != null)
114 respStream.Close();
115 resp.Close();
116 }
117 } 107 }
108
118 return deserial; 109 return deserial;
119 } 110 }
120 } 111 }
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
228 errorMessage = we.Message; 228 errorMessage = we.Message;
229 if (we.Status == WebExceptionStatus.ProtocolError) 229 if (we.Status == WebExceptionStatus.ProtocolError)
230 { 230 {
231 HttpWebResponse webResponse = (HttpWebResponse)we.Response; 231 using (HttpWebResponse webResponse = (HttpWebResponse)we.Response)
232 errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription); 232 errorMessage = String.Format("[{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription);
233 } 233 }
234 } 234 }
235 catch (Exception ex) 235 catch (Exception ex)
@@ -387,8 +387,8 @@ namespace OpenSim.Framework
387 errorMessage = we.Message; 387 errorMessage = we.Message;
388 if (we.Status == WebExceptionStatus.ProtocolError) 388 if (we.Status == WebExceptionStatus.ProtocolError)
389 { 389 {
390 HttpWebResponse webResponse = (HttpWebResponse)we.Response; 390 using (HttpWebResponse webResponse = (HttpWebResponse)we.Response)
391 errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription); 391 errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription);
392 } 392 }
393 } 393 }
394 catch (Exception ex) 394 catch (Exception ex)
@@ -834,15 +834,16 @@ namespace OpenSim.Framework
834 { 834 {
835 if (e.Response is HttpWebResponse) 835 if (e.Response is HttpWebResponse)
836 { 836 {
837 HttpWebResponse httpResponse = (HttpWebResponse)e.Response; 837 using (HttpWebResponse httpResponse = (HttpWebResponse)e.Response)
838 838 {
839 if (httpResponse.StatusCode != HttpStatusCode.NotFound) 839 if (httpResponse.StatusCode != HttpStatusCode.NotFound)
840 { 840 {
841 // We don't appear to be handling any other status codes, so log these feailures to that 841 // We don't appear to be handling any other status codes, so log these feailures to that
842 // people don't spend unnecessary hours hunting phantom bugs. 842 // people don't spend unnecessary hours hunting phantom bugs.
843 m_log.DebugFormat( 843 m_log.DebugFormat(
844 "[ASYNC REQUEST]: Request {0} {1} failed with unexpected status code {2}", 844 "[ASYNC REQUEST]: Request {0} {1} failed with unexpected status code {2}",
845 verb, requestUrl, httpResponse.StatusCode); 845 verb, requestUrl, httpResponse.StatusCode);
846 }
846 } 847 }
847 } 848 }
848 } 849 }
@@ -983,11 +984,9 @@ namespace OpenSim.Framework
983 Stream respStream = null; 984 Stream respStream = null;
984 try 985 try
985 { 986 {
986 respStream = resp.GetResponseStream(); 987 using (respStream = resp.GetResponseStream())
987 using (StreamReader reader = new StreamReader(respStream)) 988 using (StreamReader reader = new StreamReader(respStream))
988 { 989 respstring = reader.ReadToEnd();
989 respstring = reader.ReadToEnd();
990 }
991 } 990 }
992 catch (Exception e) 991 catch (Exception e)
993 { 992 {
@@ -1127,10 +1126,11 @@ namespace OpenSim.Framework
1127 { 1126 {
1128 if (resp.ContentLength != 0) 1127 if (resp.ContentLength != 0)
1129 { 1128 {
1130 Stream respStream = resp.GetResponseStream(); 1129 using (Stream respStream = resp.GetResponseStream())
1131 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); 1130 {
1132 deserial = (TResponse)deserializer.Deserialize(respStream); 1131 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
1133 respStream.Close(); 1132 deserial = (TResponse)deserializer.Deserialize(respStream);
1133 }
1134 } 1134 }
1135 else 1135 else
1136 { 1136 {
@@ -1142,14 +1142,15 @@ namespace OpenSim.Framework
1142 } 1142 }
1143 catch (WebException e) 1143 catch (WebException e)
1144 { 1144 {
1145 HttpWebResponse hwr = (HttpWebResponse)e.Response; 1145 using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
1146 1146 {
1147 if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound) 1147 if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound)
1148 return deserial; 1148 return deserial;
1149 else 1149 else
1150 m_log.ErrorFormat( 1150 m_log.ErrorFormat(
1151 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2}: {3} {4}", 1151 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2}: {3} {4}",
1152 verb, requestUrl, typeof(TResponse).ToString(), e.Message, e.StackTrace); 1152 verb, requestUrl, typeof(TResponse).ToString(), e.Message, e.StackTrace);
1153 }
1153 } 1154 }
1154 catch (System.InvalidOperationException) 1155 catch (System.InvalidOperationException)
1155 { 1156 {