Make sure we dispose of WebResponse, StreamReader and Stream in various places where we were not already.

This commit is contained in:
Justin Clark-Casey (justincc)
2013-02-27 00:21:02 +00:00
parent 2bfbfc5725
commit 80c19b7cac
14 changed files with 243 additions and 210 deletions

View File

@@ -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
}
}
}
}
}