Make sure we dispose of WebResponse, StreamReader and Stream in various places where we were not already.
parent
c80009e86c
commit
ce2bf496a4
|
@ -44,7 +44,6 @@ namespace OpenSim.ConsoleClient
|
|||
ReplyDelegate action)
|
||||
{
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
WebResponse response = null;
|
||||
|
||||
request.Method = "POST";
|
||||
|
||||
|
@ -64,17 +63,19 @@ namespace OpenSim.ConsoleClient
|
|||
{
|
||||
string reply = String.Empty;
|
||||
|
||||
response = request.EndGetResponse(ar);
|
||||
|
||||
using (WebResponse response = request.EndGetResponse(ar))
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamReader r = new StreamReader(response.GetResponseStream());
|
||||
using (Stream s = response.GetResponseStream())
|
||||
using (StreamReader r = new StreamReader(s))
|
||||
reply = r.ReadToEnd();
|
||||
|
||||
}
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
action(requestUrl, data, reply);
|
||||
}, null);
|
||||
|
|
|
@ -65,10 +65,10 @@ 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();
|
||||
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
using (Stream resStream = response.GetResponseStream())
|
||||
{
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
|
@ -80,9 +80,13 @@ namespace OpenSim.Framework.Configuration.HTTP
|
|||
tempString = Util.UTF8.GetString(buf, 0, count);
|
||||
sb.Append(tempString);
|
||||
}
|
||||
} while (count > 0);
|
||||
}
|
||||
while (count > 0);
|
||||
|
||||
LoadDataFromString(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException)
|
||||
{
|
||||
m_log.Warn("Unable to connect to remote configuration 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;
|
||||
|
||||
using (HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse())
|
||||
{
|
||||
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 (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
if (!allowRegionless)
|
||||
throw ex;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (regionCount > 0 | allowRegionless)
|
||||
{
|
||||
return regionInfos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("[WEBLOADER]: No region configs were available.");
|
||||
|
|
|
@ -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,7 +387,7 @@ namespace OpenSim.Framework
|
|||
errorMessage = we.Message;
|
||||
if (we.Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
HttpWebResponse webResponse = (HttpWebResponse)we.Response;
|
||||
using (HttpWebResponse webResponse = (HttpWebResponse)we.Response)
|
||||
errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription);
|
||||
}
|
||||
}
|
||||
|
@ -823,8 +823,8 @@ namespace OpenSim.Framework
|
|||
{
|
||||
if (e.Response is HttpWebResponse)
|
||||
{
|
||||
HttpWebResponse httpResponse = (HttpWebResponse)e.Response;
|
||||
|
||||
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
|
||||
|
@ -835,6 +835,7 @@ namespace OpenSim.Framework
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
|
@ -972,12 +973,10 @@ namespace OpenSim.Framework
|
|||
Stream respStream = null;
|
||||
try
|
||||
{
|
||||
respStream = resp.GetResponseStream();
|
||||
using (respStream = resp.GetResponseStream())
|
||||
using (StreamReader reader = new StreamReader(respStream))
|
||||
{
|
||||
respstring = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
|
@ -1102,10 +1101,11 @@ namespace OpenSim.Framework
|
|||
{
|
||||
if (resp.ContentLength != 0)
|
||||
{
|
||||
Stream respStream = resp.GetResponseStream();
|
||||
using (Stream respStream = resp.GetResponseStream())
|
||||
{
|
||||
XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
|
||||
deserial = (TResponse)deserializer.Deserialize(respStream);
|
||||
respStream.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1117,8 +1117,8 @@ namespace OpenSim.Framework
|
|||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
HttpWebResponse hwr = (HttpWebResponse)e.Response;
|
||||
|
||||
using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
|
||||
{
|
||||
if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound)
|
||||
return deserial;
|
||||
else
|
||||
|
@ -1126,6 +1126,7 @@ namespace OpenSim.Framework
|
|||
"[SynchronousRestObjectRequester]: WebException for {0} {1} {2}: {3} {4}",
|
||||
verb, requestUrl, typeof(TResponse).ToString(), e.Message, e.StackTrace);
|
||||
}
|
||||
}
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
// This is what happens when there is invalid XML
|
||||
|
|
|
@ -826,15 +826,19 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
|
|||
try
|
||||
{
|
||||
WebRequest request = HttpWebRequest.Create(url);
|
||||
//Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used.
|
||||
//Ckrinke Stream str = null;
|
||||
HttpWebResponse response = (HttpWebResponse)(request).GetResponse();
|
||||
|
||||
using (HttpWebResponse response = (HttpWebResponse)(request).GetResponse())
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Bitmap image = new Bitmap(response.GetResponseStream());
|
||||
using (Stream s = response.GetResponseStream())
|
||||
{
|
||||
Bitmap image = new Bitmap(s);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
|
|
|
@ -863,14 +863,15 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
|
|||
}
|
||||
|
||||
string response_mapItems_reply = null;
|
||||
{ // get the response
|
||||
StreamReader sr = null;
|
||||
{
|
||||
try
|
||||
{
|
||||
WebResponse webResponse = mapitemsrequest.GetResponse();
|
||||
using (WebResponse webResponse = mapitemsrequest.GetResponse())
|
||||
{
|
||||
if (webResponse != null)
|
||||
{
|
||||
sr = new StreamReader(webResponse.GetResponseStream());
|
||||
using (Stream s = webResponse.GetResponseStream())
|
||||
using (StreamReader sr = new StreamReader(s))
|
||||
response_mapItems_reply = sr.ReadToEnd().Trim();
|
||||
}
|
||||
else
|
||||
|
@ -878,6 +879,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
|
|||
return new OSDMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException)
|
||||
{
|
||||
responseMap["connect"] = OSD.FromBoolean(false);
|
||||
|
@ -903,11 +905,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
|
|||
|
||||
return responseMap;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (sr != null)
|
||||
sr.Close();
|
||||
}
|
||||
|
||||
OSD rezResponse = null;
|
||||
try
|
||||
|
@ -921,6 +918,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
|
|||
{
|
||||
m_log.InfoFormat("[WORLD MAP]: exception on parse of RequestMapItems reply from {0}: {1}", httpserver, ex.Message);
|
||||
responseMap["connect"] = OSD.FromBoolean(false);
|
||||
|
||||
lock (m_blacklistedregions)
|
||||
{
|
||||
if (!m_blacklistedregions.ContainsKey(regionhandle))
|
||||
|
|
|
@ -551,13 +551,20 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
|
|||
reqStream.Close();
|
||||
}
|
||||
|
||||
HttpWebResponse fwdrsp = (HttpWebResponse)forwardreq.GetResponse();
|
||||
using (HttpWebResponse fwdrsp = (HttpWebResponse)forwardreq.GetResponse())
|
||||
{
|
||||
Encoding encoding = Util.UTF8;
|
||||
StreamReader fwdresponsestream = new StreamReader(fwdrsp.GetResponseStream(), encoding);
|
||||
|
||||
using (Stream s = fwdrsp.GetResponseStream())
|
||||
{
|
||||
using (StreamReader fwdresponsestream = new StreamReader(s))
|
||||
{
|
||||
fwdresponsestr = fwdresponsestream.ReadToEnd();
|
||||
fwdresponsecontenttype = fwdrsp.ContentType;
|
||||
fwdresponsecode = (int)fwdrsp.StatusCode;
|
||||
fwdresponsestream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response["content_type"] = fwdresponsecontenttype;
|
||||
response["str_response_string"] = fwdresponsestr;
|
||||
|
|
|
@ -1115,17 +1115,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice
|
|||
m_log.DebugFormat("[VivoxVoice] Sending request <{0}>", requrl);
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requrl);
|
||||
HttpWebResponse rsp = null;
|
||||
|
||||
// We are sending just parameters, no content
|
||||
req.ContentLength = 0;
|
||||
|
||||
// Send request and retrieve the response
|
||||
rsp = (HttpWebResponse)req.GetResponse();
|
||||
|
||||
XmlTextReader rdr = new XmlTextReader(rsp.GetResponseStream());
|
||||
using (HttpWebResponse rsp = (HttpWebResponse)req.GetResponse())
|
||||
using (Stream s = rsp.GetResponseStream())
|
||||
using (XmlTextReader rdr = new XmlTextReader(s))
|
||||
doc.Load(rdr);
|
||||
rdr.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -1151,17 +1151,25 @@ namespace Nwc.XmlRpc
|
|||
request.AllowWriteStreamBuffering = true;
|
||||
request.KeepAlive = !_disableKeepAlive;
|
||||
|
||||
Stream stream = request.GetRequestStream();
|
||||
XmlTextWriter xml = new XmlTextWriter(stream, Encoding.ASCII);
|
||||
using (Stream stream = request.GetRequestStream())
|
||||
{
|
||||
using (XmlTextWriter xml = new XmlTextWriter(stream, Encoding.ASCII))
|
||||
{
|
||||
_serializer.Serialize(xml, this);
|
||||
xml.Flush();
|
||||
xml.Close();
|
||||
}
|
||||
}
|
||||
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
StreamReader input = new StreamReader(response.GetResponseStream());
|
||||
|
||||
string inputXml = input.ReadToEnd();
|
||||
XmlRpcResponse resp;
|
||||
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
using (Stream s = response.GetResponseStream())
|
||||
{
|
||||
using (StreamReader input = new StreamReader(s))
|
||||
{
|
||||
string inputXml = input.ReadToEnd();
|
||||
|
||||
try
|
||||
{
|
||||
resp = (XmlRpcResponse)_deserializer.Deserialize(inputXml);
|
||||
|
@ -1171,8 +1179,10 @@ namespace Nwc.XmlRpc
|
|||
RequestResponse = inputXml;
|
||||
throw e;
|
||||
}
|
||||
input.Close();
|
||||
response.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ namespace OpenSim.Services.Connectors
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual string Helo()
|
||||
{
|
||||
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI);
|
||||
|
@ -82,11 +81,13 @@ namespace OpenSim.Services.Connectors
|
|||
|
||||
try
|
||||
{
|
||||
WebResponse response = req.GetResponse();
|
||||
using (WebResponse response = req.GetResponse())
|
||||
{
|
||||
if (response.Headers.Get("X-Handlers-Provided") == null) // just in case this ever returns a null
|
||||
return string.Empty;
|
||||
return response.Headers.Get("X-Handlers-Provided");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[HELO SERVICE]: Unable to perform HELO request to {0}: {1}", m_ServerURI, e.Message);
|
||||
|
@ -95,6 +96,5 @@ namespace OpenSim.Services.Connectors
|
|||
// fail
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -171,19 +171,20 @@ 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();
|
||||
using (WebResponse webResponse = AgentCreateRequest.GetResponse())
|
||||
{
|
||||
if (webResponse == null)
|
||||
{
|
||||
m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
sr = new StreamReader(webResponse.GetResponseStream());
|
||||
using (Stream s = webResponse.GetResponseStream())
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(s))
|
||||
{
|
||||
string response = sr.ReadToEnd().Trim();
|
||||
m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response);
|
||||
|
||||
|
@ -210,17 +211,15 @@ namespace OpenSim.Services.Connectors.Hypergrid
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
|
||||
reason = "Destination did not reply";
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (sr != null)
|
||||
sr.Close();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
|
|
@ -168,10 +168,10 @@ namespace OpenSim.Services.Connectors
|
|||
// Let's wait for the response
|
||||
//m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall");
|
||||
|
||||
StreamReader sr = null;
|
||||
try
|
||||
{
|
||||
WebResponse webResponse = helloNeighbourRequest.GetResponse();
|
||||
using (WebResponse webResponse = helloNeighbourRequest.GetResponse())
|
||||
{
|
||||
if (webResponse == null)
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
|
@ -179,11 +179,16 @@ namespace OpenSim.Services.Connectors
|
|||
thisRegion.RegionName, region.RegionName);
|
||||
}
|
||||
|
||||
sr = new StreamReader(webResponse.GetResponseStream());
|
||||
using (Stream s = webResponse.GetResponseStream())
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(s))
|
||||
{
|
||||
//reply = sr.ReadToEnd().Trim();
|
||||
sr.ReadToEnd().Trim();
|
||||
//m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -193,11 +198,6 @@ namespace OpenSim.Services.Connectors
|
|||
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (sr != null)
|
||||
sr.Close();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -340,7 +340,8 @@ namespace OpenSim.Services.Connectors.SimianGrid
|
|||
// By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs
|
||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString());
|
||||
|
||||
HttpWebResponse response = MultipartForm.Post(request, postParameters);
|
||||
using (HttpWebResponse response = MultipartForm.Post(request, postParameters))
|
||||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
string responseStr = null;
|
||||
|
@ -371,6 +372,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
errorMessage = ex.Message;
|
||||
|
@ -378,6 +380,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
|
|||
|
||||
m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}",
|
||||
asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue