From bffdf20721d8831f86bd0320ba304ebf0959656d Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 29 Oct 2012 23:22:40 +0000 Subject: [PATCH] Fix memory leak where removing an NPC did not remove its circuits. This was because we were removing by circuitcode where NPCs have no code. Now removing by agent ID instead. This commit also fixes the "show circuits" console command to work properly where the circuit has no associated IP address. --- OpenSim/Region/Application/OpenSim.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 5 +++-- .../OptionalModules/World/NPC/Tests/NPCModuleTests.cs | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 751923f433..cc5c264ab4 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -1109,7 +1109,7 @@ namespace OpenSim aCircuit.Name, aCircuit.child ? "child" : "root", aCircuit.circuitcode.ToString(), - aCircuit.IPAddress.ToString(), + aCircuit.IPAddress != null ? aCircuit.IPAddress.ToString() : "not set", aCircuit.Viewer); }); diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index b5640b1e6a..6c1d434575 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -3333,9 +3333,10 @@ namespace OpenSim.Region.Framework.Scenes } else { - // We remove the acd up here to avoid later raec conditions if two RemoveClient() calls occurred + // We remove the acd up here to avoid later race conditions if two RemoveClient() calls occurred // simultaneously. - m_authenticateHandler.RemoveCircuit(acd.circuitcode); + // We also need to remove by agent ID since NPCs will have no circuit code. + m_authenticateHandler.RemoveCircuit(agentID); } } diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 91799667ab..52ed8468c6 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -117,6 +117,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(npc, Is.Not.Null); Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId)); Assert.That(m_umMod.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname))); + + IClientAPI client; + Assert.That(m_scene.TryGetClient(npcId, out client), Is.True); + + // Have to account for both SP and NPC. + Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(2)); } [Test] @@ -136,6 +142,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests ScenePresence deletedNpc = m_scene.GetScenePresence(npcId); Assert.That(deletedNpc, Is.Null); + IClientAPI client; + Assert.That(m_scene.TryGetClient(npcId, out client), Is.False); + + // Have to account for SP still present. + Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); } [Test]