From b8e22f02e79e84d29e65a46751d68235f93aa8e8 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Thu, 19 Dec 2013 14:08:46 +0200 Subject: Make sure Web streams are disposed after use --- OpenSim/Framework/WebUtil.cs | 6 +- .../Avatar/UserProfiles/UserProfileModule.cs | 77 ++++++++++------------ .../Scripting/HttpRequest/ScriptsHttpRequests.cs | 7 +- .../CoreModules/World/WorldMap/WorldMapModule.cs | 2 +- .../RegionReadyModule/RegionReadyModule.cs | 2 +- .../Neighbour/NeighbourServicesConnector.cs | 4 +- 6 files changed, 45 insertions(+), 53 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index bcf6af8..54a6c0c 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -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); @@ -1268,4 +1268,4 @@ namespace OpenSim.Framework return deserial; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs index b21082f..9ae7452 100644 --- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs @@ -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 - { - mret = (OSDMap)OSDParser.DeserializeJson(rstream); - } - catch (Exception e) + using (webResponse) + using (Stream rstream = webResponse.GetResponseStream()) { - m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message); - return false; - } + OSDMap mret = (OSDMap)OSDParser.DeserializeJson(rstream); + if (mret.ContainsKey("error")) + return false; - if (mret.ContainsKey("error")) - return false; - - // get params... - OSD.DeserializeMembers(ref parameters, (OSDMap) mret["result"]); - return true; + // get params... + OSD.DeserializeMembers(ref parameters, (OSDMap)mret["result"]); + return true; + } } /// @@ -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 - { - response = (OSDMap)OSDParser.DeserializeJson(rstream); - } - catch (Exception e) + using (webResponse) + using (Stream rstream = webResponse.GetResponseStream()) { - 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; + data = response; - return true; + return true; + } } + #endregion Web Util } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index c3a8afd..a7237ea 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs @@ -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 @@ -584,4 +583,4 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest Request.Abort(); } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index cf2ef29..03e044b 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -915,7 +915,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap finally { if (os != null) - os.Close(); + os.Dispose(); } string response_mapItems_reply = null; diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs index eb386fe..e10b9ad 100644 --- a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs @@ -301,7 +301,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady finally { if (os != null) - os.Close(); + os.Dispose(); } } } diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs index 774fe2a..96a756d 100644 --- a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs +++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs @@ -162,7 +162,7 @@ namespace OpenSim.Services.Connectors finally { if (os != null) - os.Close(); + os.Dispose(); } // Let's wait for the response @@ -202,4 +202,4 @@ namespace OpenSim.Services.Connectors return true; } } -} \ No newline at end of file +} -- cgit v1.1