summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-12 07:13:48 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-12 07:13:48 -0600
commitf3796c231d5bcac6850fb9afc8db652361e3fceb (patch)
treedf79d9614dc601cfc1ee77fcd42a77caef389858
parente2d60401eaf55abe9e2251854f3174ffe0f4ad9e (diff)
downloadmana-f3796c231d5bcac6850fb9afc8db652361e3fceb.tar.gz
mana-f3796c231d5bcac6850fb9afc8db652361e3fceb.tar.bz2
mana-f3796c231d5bcac6850fb9afc8db652361e3fceb.tar.xz
mana-f3796c231d5bcac6850fb9afc8db652361e3fceb.zip
Fix leaks in status effects
-rw-r--r--src/main.cpp5
-rw-r--r--src/statuseffect.cpp28
-rw-r--r--src/statuseffect.h4
3 files changed, 23 insertions, 14 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 0034fc60..f1424096 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -51,6 +51,7 @@
#include "player_relations.h"
#include "serverinfo.h"
#include "sound.h"
+#include "statuseffect.h"
#include "units.h"
#include "gui/button.h"
@@ -488,6 +489,7 @@ void exit_engine()
ItemDB::unload();
MonsterDB::unload();
NPCDB::unload();
+ StatusEffect::unload();
ResourceManager::deleteInstance();
delete logger;
@@ -946,7 +948,8 @@ int main(int argc, char *argv[])
MonsterDB::load();
NPCDB::load();
EmoteDB::load();
- Being::load(); // Hairstyles and emotions
+ StatusEffect::load();
+ Being::load(); // Hairstyles
state = CHAR_CONNECT_STATE;
break;
diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp
index c0d689f0..70e8d59f 100644
--- a/src/statuseffect.cpp
+++ b/src/statuseffect.cpp
@@ -92,7 +92,6 @@ static std::map<int, int> blockEffectIndexMap;
int StatusEffect::blockEffectIndexToEffectIndex(int blockIndex)
{
- load();
if (blockEffectIndexMap.find(blockIndex) == blockEffectIndexMap.end())
return -1;
return blockEffectIndexMap[blockIndex];
@@ -100,27 +99,16 @@ int StatusEffect::blockEffectIndexToEffectIndex(int blockIndex)
StatusEffect *StatusEffect::getStatusEffect(int index, bool enabling)
{
- load();
return statusEffects[enabling][index];
}
StatusEffect *StatusEffect::getStunEffect(int index, bool enabling)
{
- load();
return stunEffects[enabling][index];
}
-static bool status_effects_loaded = false;
-
-
-
void StatusEffect::load()
{
- if (status_effects_loaded)
- return;
-
- status_effects_loaded = true;
-
XML::Document doc(STATUS_EFFECTS_FILE);
xmlNodePtr rootNode = doc.rootNode();
@@ -168,3 +156,19 @@ void StatusEffect::load()
}
}
}
+
+void unloadMap(std::map<int, StatusEffect *> map)
+{
+ std::map<int, StatusEffect *>::iterator it;
+
+ for (it = map.begin(); it != map.end(); it++)
+ delete (*it).second;
+}
+
+void StatusEffect::unload()
+{
+ unloadMap(statusEffects[0]);
+ unloadMap(statusEffects[1]);
+ unloadMap(stunEffects[0]);
+ unloadMap(stunEffects[1]);
+} \ No newline at end of file
diff --git a/src/statuseffect.h b/src/statuseffect.h
index 16fed69a..f1af93d2 100644
--- a/src/statuseffect.h
+++ b/src/statuseffect.h
@@ -94,9 +94,11 @@ public:
*/
static int blockEffectIndexToEffectIndex(int blocKIndex);
-private:
static void load();
+ static void unload();
+private:
+
std::string mMessage;
std::string mSFXEffect;
std::string mParticleEffect;