-fix for issue 424 (memory leak in thisforeach)
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-06-14 13:21:08 +00:00
parent 7b2c4f84a0
commit 12ee47ad24
+32 -29
View File
@@ -38,37 +38,37 @@ int AbilityFactory::countCards(TargetChooser * tc, Player * player, int option){
Counter * AbilityFactory::parseCounter(string s, MTGCardInstance * target, Spell * spell) { Counter * AbilityFactory::parseCounter(string s, MTGCardInstance * target, Spell * spell) {
int nb = 1; int nb = 1;
string name = ""; string name = "";
size_t start = 0; size_t start = 0;
size_t end = s.length(); size_t end = s.length();
size_t separator = s.find(",", start); size_t separator = s.find(",", start);
if (separator == string::npos) separator = s.find(".", start); if (separator == string::npos) separator = s.find(".", start);
if (separator != string::npos){ if (separator != string::npos){
size_t separator2 = s.find(",", separator+1); size_t separator2 = s.find(",", separator+1);
if (separator2 == string::npos) separator2 = s.find(".", separator+1); if (separator2 == string::npos) separator2 = s.find(".", separator+1);
if (separator2 != string::npos) { if (separator2 != string::npos) {
name = s.substr(separator2+1,end-separator2-1); name = s.substr(separator2+1,end-separator2-1);
}
string nbstr = s.substr(separator+1,separator2-separator-1);
WParsedInt * wpi;
if (target){
wpi = NEW WParsedInt(nbstr,spell,target);
}else{
wpi = NEW WParsedInt(atoi(nbstr.c_str()));
}
nb = wpi->getValue();
delete(wpi);
end = separator;
} }
string nbstr = s.substr(separator+1,separator2-separator-1);
WParsedInt * wpi;
if (target){
wpi = NEW WParsedInt(nbstr,spell,target);
}else{
wpi = NEW WParsedInt(atoi(nbstr.c_str()));
}
nb = wpi->getValue();
delete(wpi);
end = separator;
}
string spt = s.substr(start,end-start); string spt = s.substr(start,end-start);
int power, toughness; int power, toughness;
if ( parsePowerToughness(spt,&power, &toughness)){ if ( parsePowerToughness(spt,&power, &toughness)){
Counter * counter = NEW Counter(target,name.c_str(),power,toughness); Counter * counter = NEW Counter(target,name.c_str(),power,toughness);
counter->nb = nb; counter->nb = nb;
return counter; return counter;
} }
return NULL; return NULL;
} }
int AbilityFactory::parsePowerToughness(string s, int *power, int *toughness){ int AbilityFactory::parsePowerToughness(string s, int *power, int *toughness){
@@ -393,6 +393,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
} }
} }
if (found != string::npos && found < lord) { if (found != string::npos && found < lord) {
//why does tc even exist here? This shouldn't happen...
SAFE_DELETE(tc); //http://code.google.com/p/wagic/issues/detail?id=424
size_t header = thises[i].size(); size_t header = thises[i].size();
size_t end = s.find(")", found+header); size_t end = s.find(")", found+header);
string s1; string s1;