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 finally
{ {
if (requestStream != null) if (requestStream != null)
requestStream.Close(); requestStream.Dispose();
// capture how much time was spent writing // capture how much time was spent writing
tickdata = Util.EnvironmentTickCountSubtract(tickstart); tickdata = Util.EnvironmentTickCountSubtract(tickstart);
@ -1183,7 +1183,7 @@ namespace OpenSim.Framework
finally finally
{ {
if (requestStream != null) if (requestStream != null)
requestStream.Close(); requestStream.Dispose();
// capture how much time was spent writing // capture how much time was spent writing
tickdata = Util.EnvironmentTickCountSubtract(tickstart); tickdata = Util.EnvironmentTickCountSubtract(tickstart);
@ -1268,4 +1268,4 @@ namespace OpenSim.Framework
return deserial; return deserial;
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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