Close streams immediately when we finish using them

This commit is contained in:
Oren Hurvitz
2014-06-01 17:39:11 +03:00
parent b81187db5a
commit 99ac770abb
34 changed files with 426 additions and 485 deletions

View File

@@ -209,7 +209,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
byte[] GetAuthInfo(UUID principalID)
@@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] SuccessResult(string token)
@@ -306,18 +306,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(t);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.GetBuffer();
return Util.DocToBytes(doc);
}
private byte[] ResultToBytes(Dictionary<string, object> result)

View File

@@ -247,7 +247,7 @@ namespace OpenSim.Server.Handlers.Avatar
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@@ -269,18 +269,7 @@ namespace OpenSim.Server.Handlers.Avatar
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
}

View File

@@ -229,7 +229,7 @@ namespace OpenSim.Server.Handlers.Friends
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@@ -261,18 +261,7 @@ namespace OpenSim.Server.Handlers.Friends
rootElement.AppendChild(message);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags)

View File

@@ -602,7 +602,7 @@ namespace OpenSim.Server.Handlers.Grid
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@@ -634,18 +634,7 @@ namespace OpenSim.Server.Handlers.Grid
rootElement.AppendChild(message);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
#endregion

View File

@@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.GridUser
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@@ -301,20 +301,8 @@ namespace OpenSim.Server.Handlers.GridUser
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
}
}
}

View File

@@ -335,7 +335,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] SuccessResult(string value)
@@ -362,7 +362,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(message);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
@@ -395,7 +395,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(message);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] BoolResult(bool value)
@@ -417,21 +417,9 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
}
#endregion
}
}

View File

@@ -191,18 +191,7 @@ namespace OpenSim.Server.Handlers.Asset
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
byte[] HandleCreateUserInventory(Dictionary<string,object> request)

View File

@@ -188,7 +188,7 @@ namespace OpenSim.Server.Handlers.MapImage
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult(string msg)
@@ -215,18 +215,7 @@ namespace OpenSim.Server.Handlers.MapImage
rootElement.AppendChild(message);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
private System.Net.IPAddress GetCallerIP(IOSHttpRequest request)

View File

@@ -265,7 +265,7 @@ namespace OpenSim.Server.Handlers.Presence
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@@ -287,18 +287,7 @@ namespace OpenSim.Server.Handlers.Presence
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
}

View File

@@ -250,14 +250,30 @@ namespace OpenSim.Server.Handlers.Simulation
return encoding.GetBytes("false");
}
string requestBody;
Stream inputStream = request;
if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
inputStream = new GZipStream(inputStream, CompressionMode.Decompress);
Stream innerStream = null;
try
{
if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
{
innerStream = inputStream;
inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
}
StreamReader reader = new StreamReader(inputStream, encoding);
using (StreamReader reader = new StreamReader(inputStream, encoding))
{
requestBody = reader.ReadToEnd();
}
}
finally
{
if (innerStream != null)
innerStream.Dispose();
inputStream.Dispose();
}
string requestBody = reader.ReadToEnd();
reader.Close();
keysvals.Add("body", requestBody);
Hashtable responsedata = new Hashtable();
@@ -461,15 +477,31 @@ namespace OpenSim.Server.Handlers.Simulation
keysvals.Add("headers", headervals);
keysvals.Add("querystringkeys", querystringkeys);
Stream inputStream = request;
if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
inputStream = new GZipStream(inputStream, CompressionMode.Decompress);
String requestBody;
Encoding encoding = Encoding.UTF8;
StreamReader reader = new StreamReader(inputStream, encoding);
string requestBody = reader.ReadToEnd();
reader.Close();
Stream inputStream = request;
Stream innerStream = null;
try
{
if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
{
innerStream = inputStream;
inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
}
using (StreamReader reader = new StreamReader(inputStream, encoding))
{
requestBody = reader.ReadToEnd();
}
}
finally
{
if (innerStream != null)
innerStream.Dispose();
inputStream.Dispose();
}
keysvals.Add("body", requestBody);
httpResponse.StatusCode = 200;

View File

@@ -315,7 +315,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@@ -337,18 +337,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
private byte[] ResultToBytes(Dictionary<string, object> result)