diff options
author | Oren Hurvitz | 2013-12-19 14:08:46 +0200 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-01-31 00:44:22 +0000 |
commit | b8e22f02e79e84d29e65a46751d68235f93aa8e8 (patch) | |
tree | e8b13e3f664cef71fc593e13e025bee95c985c86 | |
parent | Made error messages more consistent (diff) | |
download | opensim-SC_OLD-b8e22f02e79e84d29e65a46751d68235f93aa8e8.zip opensim-SC_OLD-b8e22f02e79e84d29e65a46751d68235f93aa8e8.tar.gz opensim-SC_OLD-b8e22f02e79e84d29e65a46751d68235f93aa8e8.tar.bz2 opensim-SC_OLD-b8e22f02e79e84d29e65a46751d68235f93aa8e8.tar.xz |
Make sure Web streams are disposed after use
6 files changed, 45 insertions, 53 deletions
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 | |||
1030 | finally | 1030 | finally |
1031 | { | 1031 | { |
1032 | if (requestStream != null) | 1032 | if (requestStream != null) |
1033 | requestStream.Close(); | 1033 | requestStream.Dispose(); |
1034 | 1034 | ||
1035 | // capture how much time was spent writing | 1035 | // capture how much time was spent writing |
1036 | tickdata = Util.EnvironmentTickCountSubtract(tickstart); | 1036 | tickdata = Util.EnvironmentTickCountSubtract(tickstart); |
@@ -1183,7 +1183,7 @@ namespace OpenSim.Framework | |||
1183 | finally | 1183 | finally |
1184 | { | 1184 | { |
1185 | if (requestStream != null) | 1185 | if (requestStream != null) |
1186 | requestStream.Close(); | 1186 | requestStream.Dispose(); |
1187 | 1187 | ||
1188 | // capture how much time was spent writing | 1188 | // capture how much time was spent writing |
1189 | tickdata = Util.EnvironmentTickCountSubtract(tickstart); | 1189 | tickdata = Util.EnvironmentTickCountSubtract(tickstart); |
@@ -1268,4 +1268,4 @@ namespace OpenSim.Framework | |||
1268 | return deserial; | 1268 | return deserial; |
1269 | } | 1269 | } |
1270 | } | 1270 | } |
1271 | } \ No newline at end of file | 1271 | } |
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 | |||
1290 | webRequest.ContentType = "application/json-rpc"; | 1290 | webRequest.ContentType = "application/json-rpc"; |
1291 | webRequest.Method = "POST"; | 1291 | webRequest.Method = "POST"; |
1292 | 1292 | ||
1293 | Stream dataStream = webRequest.GetRequestStream(); | 1293 | using (Stream dataStream = webRequest.GetRequestStream()) |
1294 | dataStream.Write(content, 0, content.Length); | 1294 | dataStream.Write(content, 0, content.Length); |
1295 | dataStream.Close(); | ||
1296 | 1295 | ||
1297 | WebResponse webResponse = null; | 1296 | WebResponse webResponse = null; |
1298 | try | 1297 | try |
@@ -1306,26 +1305,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles | |||
1306 | return false; | 1305 | return false; |
1307 | } | 1306 | } |
1308 | 1307 | ||
1309 | Stream rstream = webResponse.GetResponseStream(); | 1308 | using (webResponse) |
1310 | 1309 | using (Stream rstream = webResponse.GetResponseStream()) | |
1311 | OSDMap mret = new OSDMap(); | ||
1312 | try | ||
1313 | { | ||
1314 | mret = (OSDMap)OSDParser.DeserializeJson(rstream); | ||
1315 | } | ||
1316 | catch (Exception e) | ||
1317 | { | 1310 | { |
1318 | m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message); | 1311 | OSDMap mret = (OSDMap)OSDParser.DeserializeJson(rstream); |
1319 | return false; | ||
1320 | } | ||
1321 | 1312 | ||
1313 | if (mret.ContainsKey("error")) | ||
1314 | return false; | ||
1322 | 1315 | ||
1323 | if (mret.ContainsKey("error")) | 1316 | // get params... |
1324 | return false; | 1317 | OSD.DeserializeMembers(ref parameters, (OSDMap)mret["result"]); |
1325 | 1318 | return true; | |
1326 | // get params... | 1319 | } |
1327 | OSD.DeserializeMembers(ref parameters, (OSDMap) mret["result"]); | ||
1328 | return true; | ||
1329 | } | 1320 | } |
1330 | 1321 | ||
1331 | /// <summary> | 1322 | /// <summary> |
@@ -1366,9 +1357,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles | |||
1366 | webRequest.ContentType = "application/json-rpc"; | 1357 | webRequest.ContentType = "application/json-rpc"; |
1367 | webRequest.Method = "POST"; | 1358 | webRequest.Method = "POST"; |
1368 | 1359 | ||
1369 | Stream dataStream = webRequest.GetRequestStream(); | 1360 | using (Stream dataStream = webRequest.GetRequestStream()) |
1370 | dataStream.Write(content, 0, content.Length); | 1361 | dataStream.Write(content, 0, content.Length); |
1371 | dataStream.Close(); | ||
1372 | 1362 | ||
1373 | WebResponse webResponse = null; | 1363 | WebResponse webResponse = null; |
1374 | try | 1364 | try |
@@ -1382,29 +1372,32 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles | |||
1382 | return false; | 1372 | return false; |
1383 | } | 1373 | } |
1384 | 1374 | ||
1385 | Stream rstream = webResponse.GetResponseStream(); | 1375 | using (webResponse) |
1386 | 1376 | using (Stream rstream = webResponse.GetResponseStream()) | |
1387 | OSDMap response = new OSDMap(); | ||
1388 | try | ||
1389 | { | ||
1390 | response = (OSDMap)OSDParser.DeserializeJson(rstream); | ||
1391 | } | ||
1392 | catch (Exception e) | ||
1393 | { | 1377 | { |
1394 | m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message); | 1378 | OSDMap response = new OSDMap(); |
1395 | return false; | 1379 | try |
1396 | } | 1380 | { |
1381 | response = (OSDMap)OSDParser.DeserializeJson(rstream); | ||
1382 | } | ||
1383 | catch (Exception e) | ||
1384 | { | ||
1385 | m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message); | ||
1386 | return false; | ||
1387 | } | ||
1397 | 1388 | ||
1398 | if(response.ContainsKey("error")) | 1389 | if (response.ContainsKey("error")) |
1399 | { | 1390 | { |
1400 | data = response["error"]; | 1391 | data = response["error"]; |
1401 | return false; | 1392 | return false; |
1402 | } | 1393 | } |
1403 | 1394 | ||
1404 | data = response; | 1395 | data = response; |
1405 | 1396 | ||
1406 | return true; | 1397 | return true; |
1398 | } | ||
1407 | } | 1399 | } |
1400 | |||
1408 | #endregion Web Util | 1401 | #endregion Web Util |
1409 | } | 1402 | } |
1410 | } \ No newline at end of file | 1403 | } |
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 | |||
488 | byte[] data = Util.UTF8.GetBytes(OutboundBody); | 488 | byte[] data = Util.UTF8.GetBytes(OutboundBody); |
489 | 489 | ||
490 | Request.ContentLength = data.Length; | 490 | Request.ContentLength = data.Length; |
491 | Stream bstream = Request.GetRequestStream(); | 491 | using (Stream bstream = Request.GetRequestStream()) |
492 | bstream.Write(data, 0, data.Length); | 492 | bstream.Write(data, 0, data.Length); |
493 | bstream.Close(); | ||
494 | } | 493 | } |
495 | 494 | ||
496 | try | 495 | try |
@@ -584,4 +583,4 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
584 | Request.Abort(); | 583 | Request.Abort(); |
585 | } | 584 | } |
586 | } | 585 | } |
587 | } \ No newline at end of file | 586 | } |
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 | |||
915 | finally | 915 | finally |
916 | { | 916 | { |
917 | if (os != null) | 917 | if (os != null) |
918 | os.Close(); | 918 | os.Dispose(); |
919 | } | 919 | } |
920 | 920 | ||
921 | string response_mapItems_reply = null; | 921 | 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 | |||
301 | finally | 301 | finally |
302 | { | 302 | { |
303 | if (os != null) | 303 | if (os != null) |
304 | os.Close(); | 304 | os.Dispose(); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | } | 307 | } |
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 | |||
162 | finally | 162 | finally |
163 | { | 163 | { |
164 | if (os != null) | 164 | if (os != null) |
165 | os.Close(); | 165 | os.Dispose(); |
166 | } | 166 | } |
167 | 167 | ||
168 | // Let's wait for the response | 168 | // Let's wait for the response |
@@ -202,4 +202,4 @@ namespace OpenSim.Services.Connectors | |||
202 | return true; | 202 | return true; |
203 | } | 203 | } |
204 | } | 204 | } |
205 | } \ No newline at end of file | 205 | } |