From 88d1c29621dd772aa3df9f6ba3c6d95e83ed5749 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Fri, 10 Mar 2017 08:49:35 +0800 Subject: [PATCH] safe delete --- projects/mtg/include/AllAbilities.h | 2 ++ projects/mtg/src/AllAbilities.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index c34159c5e..5ecb0240b 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -2102,6 +2102,7 @@ public: int resolve(); const string getMenuText(); AALibraryBottom * clone() const; + ~AALibraryBottom(); }; //Copier. ActivatedAbility @@ -2115,6 +2116,7 @@ public: int resolve(); const string getMenuText(); AACopier * clone() const; + ~AACopier(); }; //phaseout class AAPhaseOut: public ActivatedAbility diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 69bdd6c6d..fa4119461 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -1543,7 +1543,15 @@ const string AALibraryBottom::getMenuText() AALibraryBottom * AALibraryBottom::clone() const { - return NEW AALibraryBottom(*this); + AALibraryBottom * a = NEW AALibraryBottom(*this); + if(andAbility) + a->andAbility = andAbility->clone(); + return a; +} + +AALibraryBottom::~AALibraryBottom() +{ + SAFE_DELETE(andAbility); } //AACopier @@ -1687,7 +1695,15 @@ const string AACopier::getMenuText() AACopier * AACopier::clone() const { - return NEW AACopier(*this); + AACopier * a = NEW AACopier(*this); + if(andAbility) + a->andAbility = andAbility->clone(); + return a; +} + +AACopier::~AACopier() +{ + SAFE_DELETE(andAbility); } //phaseout @@ -4295,10 +4311,14 @@ ostream& AACloner::toString(ostream& out) const AACloner * AACloner::clone() const { - return NEW AACloner(*this); + AACloner * a = NEW AACloner(*this); + if(andAbility) + a->andAbility = andAbility->clone(); + return a; } AACloner::~AACloner() { + SAFE_DELETE(andAbility); } // Cast/Play Restriction modifier