From: <ral...@us...> - 2013-12-03 20:30:38
|
Revision: 9049 http://sourceforge.net/p/planeshift/code/9049 Author: ralphcampbell Date: 2013-12-03 20:30:34 +0000 (Tue, 03 Dec 2013) Log Message: ----------- Fix some memory leaks in psnpcclient found with valgrind. Modified Paths: -------------- trunk/src/common/engine/colldet.cpp trunk/src/common/engine/colldet.h trunk/src/npcclient/networkmgr.cpp trunk/src/npcclient/npc.cpp trunk/src/npcclient/npc.h trunk/src/npcclient/npcclient.cpp trunk/src/npcclient/npcoperations.cpp trunk/src/npcclient/npcoperations.h trunk/src/npcclient/recipetreenode.cpp trunk/src/npcclient/recipetreenode.h trunk/src/npcclient/tribe.cpp Modified: trunk/src/common/engine/colldet.cpp =================================================================== --- trunk/src/common/engine/colldet.cpp 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/common/engine/colldet.cpp 2013-12-03 20:30:34 UTC (rev 9049) @@ -54,7 +54,7 @@ psCollisionDetection::psCollisionDetection (iObjectRegistry* object_reg) { - cdsys = csQueryRegistry<iCollideSystem> (object_reg); + csRef<iCollideSystem> cdsys = csQueryRegistry<iCollideSystem> (object_reg); if (!cdsys) { return; @@ -62,7 +62,7 @@ colliderActor.SetCollideSystem (cdsys); colliderActor.SetGravity (19.2f); - engine = csQueryRegistry<iEngine> (object_reg); + csRef<iEngine> engine = csQueryRegistry<iEngine> (object_reg); if (!engine) { return; Modified: trunk/src/common/engine/colldet.h =================================================================== --- trunk/src/common/engine/colldet.h 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/common/engine/colldet.h 2013-12-03 20:30:34 UTC (rev 9049) @@ -77,9 +77,6 @@ csColliderActor colliderActor; - csRef<iCollideSystem> cdsys; - csWeakRef<iEngine> engine; - bool useCD; ///< Enable collision detection flag. //Collision vars Modified: trunk/src/npcclient/networkmgr.cpp =================================================================== --- trunk/src/npcclient/networkmgr.cpp 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/networkmgr.cpp 2013-12-03 20:30:34 UTC (rev 9049) @@ -1801,7 +1801,9 @@ // reconnect which will cause BIG problems. Disconnect(); CPrintf(CON_WARNING, "Reconnect disabled...\n"); - exit(-1); +#if 1 + npcclient->GetEventManager()->Stop(); +#else if(!reconnect && false) { connected = ready = false; @@ -1815,6 +1817,7 @@ psNPCReconnect* recon = new psNPCReconnect(60000, this, false); npcclient->GetEventManager()->Push(recon); } +#endif } void NetworkManager::HandleNPCWorkDone(MsgEntry* me) Modified: trunk/src/npcclient/npc.cpp =================================================================== --- trunk/src/npcclient/npc.cpp 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/npc.cpp 2013-12-03 20:30:34 UTC (rev 9049) @@ -1756,6 +1756,11 @@ //----------------------------------------------------------------------------- +HateList::~HateList() +{ + Clear(); +} + void HateList::AddHate(EID entity_id, float delta) { HateListEntry* h = hatelist.Get(entity_id, 0); @@ -1819,11 +1824,19 @@ bool HateList::Remove(EID entity_id) { + HateListEntry* h = hatelist.Get(entity_id, 0); + if(h) + delete h; return hatelist.DeleteAll(entity_id); } void HateList::Clear() { + csHash<HateListEntry*, EID>::GlobalIterator iter = hatelist.GetIterator(); + while(iter.HasNext()) + { + delete iter.Next(); + } hatelist.DeleteAll(); } Modified: trunk/src/npcclient/npc.h =================================================================== --- trunk/src/npcclient/npc.h 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/npc.h 2013-12-03 20:30:34 UTC (rev 9049) @@ -86,6 +86,7 @@ this->engine = engine; this->world = world; } + ~HateList(); void AddHate(EID entity_id, float delta); Modified: trunk/src/npcclient/npcclient.cpp =================================================================== --- trunk/src/npcclient/npcclient.cpp 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/npcclient.cpp 2013-12-03 20:30:34 UTC (rev 9049) @@ -91,6 +91,7 @@ psNPCClient::psNPCClient() : serverconsole(NULL) { npcclient = this; // Static pointer to self + connection = NULL; world = NULL; // PFMaps = NULL; pathNetwork = NULL; @@ -107,9 +108,11 @@ psNPCClient::~psNPCClient() { + csArray<Tribe*>::Iterator tribeIter(tribes.GetIterator()); + while(tribeIter.HasNext()) + delete tribeIter.Next(); + tribes.Empty(); - - csArray<NPC*>::Iterator npcIter(npcs.GetIterator()); while(npcIter.HasNext()) delete npcIter.Next(); @@ -125,6 +128,7 @@ delete mathScriptEngine; running = false; + delete connection; delete network; delete serverconsole; delete database; Modified: trunk/src/npcclient/npcoperations.cpp =================================================================== --- trunk/src/npcclient/npcoperations.cpp 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/npcoperations.cpp 2013-12-03 20:30:34 UTC (rev 9049) @@ -3549,6 +3549,7 @@ // Internal variables set to defaults path = NULL; + delete anchor; anchor = NULL; return true; } @@ -3560,11 +3561,6 @@ op->pathname = pathname; op->anim = anim; op->direction = direction; - - // Internal variables set to defaults - op->path = NULL; - op->anchor = NULL; - return op; } @@ -5270,6 +5266,7 @@ WanderOperation::~WanderOperation() { + delete currentPathPointIterator; } Modified: trunk/src/npcclient/npcoperations.h =================================================================== --- trunk/src/npcclient/npcoperations.h 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/npcoperations.h 2013-12-03 20:30:34 UTC (rev 9049) @@ -1056,8 +1056,8 @@ public: - MovePathOperation(): ScriptOperation("MovePath") { path=NULL; } - virtual ~MovePathOperation() { } + MovePathOperation(): ScriptOperation("MovePath"), anchor(0), path(0) { } + virtual ~MovePathOperation() { delete anchor; } virtual bool Load(iDocumentNode* node); virtual ScriptOperation* MakeCopy(); Modified: trunk/src/npcclient/recipetreenode.cpp =================================================================== --- trunk/src/npcclient/recipetreenode.cpp 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/recipetreenode.cpp 2013-12-03 20:30:34 UTC (rev 9049) @@ -56,6 +56,14 @@ requirementParseType = REQ_CONCENTRATED; } +RecipeTreeNode::~RecipeTreeNode() +{ + while(!children.IsEmpty()) + { + delete children.Pop(); + } +} + void RecipeTreeNode::AddChild(RecipeTreeNode* child) { children.Push(child); @@ -86,6 +94,7 @@ if(children[i] == child) { children.Delete(child); + delete child; return true; } if(children[i]->RemoveChild(child)) Modified: trunk/src/npcclient/recipetreenode.h =================================================================== --- trunk/src/npcclient/recipetreenode.h 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/recipetreenode.h 2013-12-03 20:30:34 UTC (rev 9049) @@ -73,6 +73,7 @@ /** Constructor */ RecipeTreeNode(Recipe* newRecipe, int newCost, RecipeTreeNode* parent = NULL); + ~RecipeTreeNode(); /** Add a new child */ void AddChild(RecipeTreeNode* child); Modified: trunk/src/npcclient/tribe.cpp =================================================================== --- trunk/src/npcclient/tribe.cpp 2013-12-02 23:06:01 UTC (rev 9048) +++ trunk/src/npcclient/tribe.cpp 2013-12-03 20:30:34 UTC (rev 9049) @@ -54,7 +54,11 @@ const char* Tribe::AssetStatusStr[] = {"ASSET_STATUS_NOT_APPLICABLE","ASSET_STATUS_NOT_USED","ASSET_STATUS_INCONSTRUCTION","ASSET_STATUS_CONSTRUCTED"}; Tribe::Tribe(EventManager *eventmngr) - :homeSector(0),accWealthGrowth(0.0),deathRate(0.0),resourceRate(0.0) + : tribalRecipe(0), + homeSector(0), + accWealthGrowth(0.0), + deathRate(0.0), + resourceRate(0.0) { lastGrowth = csGetTicks(); lastDeath = csGetTicks(); @@ -65,6 +69,11 @@ Tribe::~Tribe() { + delete tribalRecipe; + + csList<Memory*>::Iterator it(memories); + while (it.HasNext()) + delete it.Next(); } bool Tribe::Load(iResultRow& row) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |