Use using() semantics in XBakesModule to ensure disposable objects are alway disposed no matter what

mb-throttle-test
Justin Clark-Casey (justincc) 2014-12-20 01:38:48 +00:00
parent 9edc5cac96
commit 798074c66f
1 changed files with 42 additions and 39 deletions

View File

@ -112,9 +112,9 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
try try
{ {
Stream s = rc.Request(m_Auth); using (Stream s = rc.Request(m_Auth))
XmlTextReader sr = new XmlTextReader(s); using (XmlTextReader sr = new XmlTextReader(s))
{
sr.ReadStartElement("BakedAppearance"); sr.ReadStartElement("BakedAppearance");
while (sr.LocalName == "BakedTexture") while (sr.LocalName == "BakedTexture")
{ {
@ -135,10 +135,9 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
sr.ReadEndElement(); sr.ReadEndElement();
} }
m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id);
sr.Close();
s.Close();
m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id);
}
return ret.ToArray(); return ret.ToArray();
} }
@ -153,9 +152,11 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
if (m_URL == String.Empty) if (m_URL == String.Empty)
return; return;
MemoryStream bakeStream = new MemoryStream(); MemoryStream reqStream;
XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null);
using (MemoryStream bakeStream = new MemoryStream())
using (XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null))
{
bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty); bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty);
for (int i = 0; i < data.Length; i++) for (int i = 0; i < data.Length; i++)
@ -175,13 +176,15 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
bakeWriter.WriteEndElement(); bakeWriter.WriteEndElement();
bakeWriter.Flush(); bakeWriter.Flush();
reqStream = new MemoryStream(bakeStream.ToArray());
}
RestClient rc = new RestClient(m_URL); RestClient rc = new RestClient(m_URL);
rc.AddResourcePath("bakes"); rc.AddResourcePath("bakes");
rc.AddResourcePath(agentId.ToString()); rc.AddResourcePath(agentId.ToString());
rc.RequestMethod = "POST"; rc.RequestMethod = "POST";
MemoryStream reqStream = new MemoryStream(bakeStream.ToArray());
Util.FireAndForget( Util.FireAndForget(
delegate delegate
{ {