mirror of
https://github.com/opensim/opensim.git
synced 2026-07-31 13:55:35 +08:00
Make sure we dispose of WebResponse, StreamReader and Stream in various places where we were not already.
This commit is contained in:
@@ -65,23 +65,27 @@ namespace OpenSim.Framework.Configuration.HTTP
|
||||
byte[] buf = new byte[8192];
|
||||
HttpWebRequest request =
|
||||
(HttpWebRequest) WebRequest.Create(remoteConfigSettings.baseConfigURL + configFileName);
|
||||
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
|
||||
|
||||
Stream resStream = response.GetResponseStream();
|
||||
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
do
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
count = resStream.Read(buf, 0, buf.Length);
|
||||
if (count != 0)
|
||||
using (Stream resStream = response.GetResponseStream())
|
||||
{
|
||||
tempString = Util.UTF8.GetString(buf, 0, count);
|
||||
sb.Append(tempString);
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
count = resStream.Read(buf, 0, buf.Length);
|
||||
if (count != 0)
|
||||
{
|
||||
tempString = Util.UTF8.GetString(buf, 0, count);
|
||||
sb.Append(tempString);
|
||||
}
|
||||
}
|
||||
while (count > 0);
|
||||
|
||||
LoadDataFromString(sb.ToString());
|
||||
}
|
||||
} while (count > 0);
|
||||
LoadDataFromString(sb.ToString());
|
||||
}
|
||||
}
|
||||
catch (WebException)
|
||||
{
|
||||
|
||||
@@ -74,16 +74,26 @@ namespace OpenSim.Framework.RegionLoader.Web
|
||||
|
||||
try
|
||||
{
|
||||
HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
|
||||
m_log.Debug("[WEBLOADER]: Downloading region information...");
|
||||
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
|
||||
string xmlSource = String.Empty;
|
||||
string tempStr = reader.ReadLine();
|
||||
while (tempStr != null)
|
||||
|
||||
using (HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse())
|
||||
{
|
||||
xmlSource = xmlSource + tempStr;
|
||||
tempStr = reader.ReadLine();
|
||||
m_log.Debug("[WEBLOADER]: Downloading region information...");
|
||||
|
||||
using (Stream s = webResponse.GetResponseStream())
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(s))
|
||||
{
|
||||
string tempStr = reader.ReadLine();
|
||||
while (tempStr != null)
|
||||
{
|
||||
xmlSource = xmlSource + tempStr;
|
||||
tempStr = reader.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " +
|
||||
xmlSource.Length);
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
@@ -107,17 +117,24 @@ namespace OpenSim.Framework.RegionLoader.Web
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
|
||||
using (HttpWebResponse response = (HttpWebResponse)ex.Response)
|
||||
{
|
||||
if (!allowRegionless)
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
if (!allowRegionless)
|
||||
throw ex;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw ex;
|
||||
}
|
||||
|
||||
if (regionCount > 0 | allowRegionless)
|
||||
{
|
||||
return regionInfos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("[WEBLOADER]: No region configs were available.");
|
||||
@@ -127,4 +144,4 @@ namespace OpenSim.Framework.RegionLoader.Web
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,20 +101,11 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
using (WebResponse resp = request.GetResponse())
|
||||
{
|
||||
XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
|
||||
Stream respStream = null;
|
||||
try
|
||||
{
|
||||
respStream = resp.GetResponseStream();
|
||||
|
||||
using (Stream respStream = resp.GetResponseStream())
|
||||
deserial = (TResponse)deserializer.Deserialize(respStream);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
if (respStream != null)
|
||||
respStream.Close();
|
||||
resp.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return deserial;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user