From 9cff0bbd7c2d1743c252af000a712f4735f3141d Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 20 Dec 2014 01:46:32 +0000 Subject: [PATCH] In XBakesModule.Get() use using() to always dispose of RestClient which disposes the stream rather than disposing the stream directly --- .../Avatar/BakedTextures/XBakesModule.cs | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs index c6c54b229e..7d2cad67c3 100644 --- a/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs @@ -103,47 +103,51 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures return null; int size = 0; - RestClient rc = new RestClient(m_URL); - List ret = new List(); - rc.AddResourcePath("bakes"); - rc.AddResourcePath(id.ToString()); - rc.RequestMethod = "GET"; - - try + using (RestClient rc = new RestClient(m_URL)) { - using (Stream s = rc.Request(m_Auth)) - using (XmlTextReader sr = new XmlTextReader(s)) + List ret = new List(); + rc.AddResourcePath("bakes"); + rc.AddResourcePath(id.ToString()); + + rc.RequestMethod = "GET"; + + try { - sr.ReadStartElement("BakedAppearance"); - while (sr.LocalName == "BakedTexture") + Stream s = rc.Request(m_Auth); + + using (XmlTextReader sr = new XmlTextReader(s)) { - string sTextureIndex = sr.GetAttribute("TextureIndex"); - int lTextureIndex = Convert.ToInt32(sTextureIndex); - string sCacheId = sr.GetAttribute("CacheId"); - UUID lCacheId = UUID.Zero; - if (!(UUID.TryParse(sCacheId, out lCacheId))) + sr.ReadStartElement("BakedAppearance"); + while (sr.LocalName == "BakedTexture") { - // ?? Nothing here + string sTextureIndex = sr.GetAttribute("TextureIndex"); + int lTextureIndex = Convert.ToInt32(sTextureIndex); + string sCacheId = sr.GetAttribute("CacheId"); + UUID lCacheId = UUID.Zero; + if (!(UUID.TryParse(sCacheId, out lCacheId))) + { + // ?? Nothing here + } + + ++size; + + sr.ReadStartElement("BakedTexture"); + AssetBase a = (AssetBase)m_serializer.Deserialize(sr); + ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID }); + + sr.ReadEndElement(); } - ++size; - - sr.ReadStartElement("BakedTexture"); - AssetBase a = (AssetBase)m_serializer.Deserialize(sr); - ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID }); - - sr.ReadEndElement(); + m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id); } - m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id); + return ret.ToArray(); + } + catch (XmlException) + { + return null; } - - return ret.ToArray(); - } - catch (XmlException) - { - return null; } }