Make sure Web streams are disposed after use

justincc-master
Oren Hurvitz 2013-12-19 14:08:46 +02:00 committed by Justin Clark-Casey (justincc)
parent 1380b37d71
commit b8e22f02e7
6 changed files with 46 additions and 54 deletions

View File

@ -1030,7 +1030,7 @@ namespace OpenSim.Framework
finally
{
if (requestStream != null)
requestStream.Close();
requestStream.Dispose();
// capture how much time was spent writing
tickdata = Util.EnvironmentTickCountSubtract(tickstart);
@ -1183,7 +1183,7 @@ namespace OpenSim.Framework
finally
{
if (requestStream != null)
requestStream.Close();
requestStream.Dispose();
// capture how much time was spent writing
tickdata = Util.EnvironmentTickCountSubtract(tickstart);

View File

@ -1290,9 +1290,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(content, 0, content.Length);
dataStream.Close();
using (Stream dataStream = webRequest.GetRequestStream())
dataStream.Write(content, 0, content.Length);
WebResponse webResponse = null;
try
@ -1306,26 +1305,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
return false;
}
Stream rstream = webResponse.GetResponseStream();
OSDMap mret = new OSDMap();
try
using (webResponse)
using (Stream rstream = webResponse.GetResponseStream())
{
mret = (OSDMap)OSDParser.DeserializeJson(rstream);
OSDMap mret = (OSDMap)OSDParser.DeserializeJson(rstream);
if (mret.ContainsKey("error"))
return false;
// get params...
OSD.DeserializeMembers(ref parameters, (OSDMap)mret["result"]);
return true;
}
catch (Exception e)
{
m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
return false;
}
if (mret.ContainsKey("error"))
return false;
// get params...
OSD.DeserializeMembers(ref parameters, (OSDMap) mret["result"]);
return true;
}
/// <summary>
@ -1366,9 +1357,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(content, 0, content.Length);
dataStream.Close();
using (Stream dataStream = webRequest.GetRequestStream())
dataStream.Write(content, 0, content.Length);
WebResponse webResponse = null;
try
@ -1382,29 +1372,32 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
return false;
}
Stream rstream = webResponse.GetResponseStream();
OSDMap response = new OSDMap();
try
using (webResponse)
using (Stream rstream = webResponse.GetResponseStream())
{
response = (OSDMap)OSDParser.DeserializeJson(rstream);
}
catch (Exception e)
{
m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
return false;
}
OSDMap response = new OSDMap();
try
{
response = (OSDMap)OSDParser.DeserializeJson(rstream);
}
catch (Exception e)
{
m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
return false;
}
if(response.ContainsKey("error"))
{
data = response["error"];
return false;
if (response.ContainsKey("error"))
{
data = response["error"];
return false;
}
data = response;
return true;
}
data = response;
return true;
}
#endregion Web Util
}
}

View File

@ -488,9 +488,8 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
byte[] data = Util.UTF8.GetBytes(OutboundBody);
Request.ContentLength = data.Length;
Stream bstream = Request.GetRequestStream();
bstream.Write(data, 0, data.Length);
bstream.Close();
using (Stream bstream = Request.GetRequestStream())
bstream.Write(data, 0, data.Length);
}
try

View File

@ -915,7 +915,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
finally
{
if (os != null)
os.Close();
os.Dispose();
}
string response_mapItems_reply = null;

View File

@ -301,7 +301,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
finally
{
if (os != null)
os.Close();
os.Dispose();
}
}
}

View File

@ -162,7 +162,7 @@ namespace OpenSim.Services.Connectors
finally
{
if (os != null)
os.Close();
os.Dispose();
}
// Let's wait for the response