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
{
Stream s = rc.Request(m_Auth);
XmlTextReader sr = new XmlTextReader(s);
using (Stream s = rc.Request(m_Auth))
using (XmlTextReader sr = new XmlTextReader(s))
{
sr.ReadStartElement("BakedAppearance");
while (sr.LocalName == "BakedTexture")
{
@ -135,10 +135,9 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
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();
}
@ -153,9 +152,11 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
if (m_URL == String.Empty)
return;
MemoryStream bakeStream = new MemoryStream();
XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null);
MemoryStream reqStream;
using (MemoryStream bakeStream = new MemoryStream())
using (XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null))
{
bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty);
for (int i = 0; i < data.Length; i++)
@ -175,13 +176,15 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
bakeWriter.WriteEndElement();
bakeWriter.Flush();
reqStream = new MemoryStream(bakeStream.ToArray());
}
RestClient rc = new RestClient(m_URL);
rc.AddResourcePath("bakes");
rc.AddResourcePath(agentId.ToString());
rc.RequestMethod = "POST";
MemoryStream reqStream = new MemoryStream(bakeStream.ToArray());
Util.FireAndForget(
delegate
{