From f3796c231d5bcac6850fb9afc8db652361e3fceb Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 12 Mar 2009 07:13:48 -0600 Subject: Fix leaks in status effects --- src/statuseffect.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/statuseffect.cpp') 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 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 map) +{ + std::map::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 -- cgit v1.2.3-60-g2f50