diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 02:07:25 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 02:07:25 +0000 |
| commit | 12d5161318a4d8d781f896812f5a95fa7b46d8a8 (patch) | |
| tree | 70617a790b791b876426d85848d20901e65d6606 /pokemod/Pokemod.cpp | |
| parent | 9a65bc6bb7c8da1dfa5b101579e52845c75848ef (diff) | |
| download | sigen-12d5161318a4d8d781f896812f5a95fa7b46d8a8.tar.gz sigen-12d5161318a4d8d781f896812f5a95fa7b46d8a8.tar.xz sigen-12d5161318a4d8d781f896812f5a95fa7b46d8a8.zip | |
[FIX] Memory leaks in load and copy method
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@96 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Pokemod.cpp')
| -rw-r--r-- | pokemod/Pokemod.cpp | 174 |
1 files changed, 113 insertions, 61 deletions
diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 3de5b185..53c1892d 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -94,36 +94,40 @@ Pokemod::Pokemod(const QString& fileName) : Pokemod::~Pokemod() { - foreach (Ability* ability, m_abilities) - delete ability; - foreach (Author* author, m_authors) - delete author; - foreach (Badge* badge, m_badges) - delete badge; - foreach (CoinList* coinList, m_coinLists) - delete coinList; - foreach (Dialog* dialog, m_dialogs) - delete dialog; - foreach (EggGroup* eggGroup, m_eggGroups) - delete eggGroup; - foreach (Item* item, m_items) - delete item; - foreach (ItemType* itemType, m_itemTypes) - delete itemType; - foreach (Map* map, m_maps) - delete map; - foreach (Species* m_species, m_species) - delete m_species; - foreach (Store* store, m_stores) - delete store; - foreach (Tile* tile, m_tiles) - delete tile; - foreach (Time* time, m_times) - delete time; - foreach (Trainer* trainer, m_trainers) - delete trainer; - foreach (Type* type, m_types) - delete type; + while (abilityCount()) + deleteAbility(0); + while (authorCount()) + deleteAuthor(0); + while (badgeCount()) + deleteBadge(0); + while (coinListCount()) + deleteCoinList(0); + while (dialogCount()) + deleteDialog(0); + while (eggGroupCount()) + deleteEggGroup(0); + while (itemCount()) + deleteItem(0); + while (itemTypeCount()) + deleteItemType(0); + while (mapCount()) + deleteMap(0); + while (moveCount()) + deleteMove(0); + while (natureCount()) + deleteNature(0); + while (speciesCount()) + deleteSpecies(0); + while (storeCount()) + deleteStore(0); + while (tileCount()) + deleteTile(0); + while (timeCount()) + deleteTime(0); + while (trainerCount()) + deleteTrainer(0); + while (typeCount()) + deleteType(0); } bool Pokemod::validate() const @@ -452,7 +456,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) QDir fdir(path()); if (QFile::exists(QString("%1/rules.pini").arg(path()))) m_rules.load(QString("%1/rules.pini").arg(path())); - m_abilities.clear(); + while (abilityCount()) + deleteAbility(0); if (fdir.cd("ability")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -460,7 +465,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newAbility(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_authors.clear(); + while (authorCount()) + deleteAuthor(0); if (fdir.cd("author")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -468,7 +474,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newAuthor(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_badges.clear(); + while (badgeCount()) + deleteBadge(0); if (fdir.cd("badge")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -476,7 +483,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newBadge(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_coinLists.clear(); + while (coinListCount()) + deleteCoinList(0); if (fdir.cd("coinlist")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -484,7 +492,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newCoinList(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_dialogs.clear(); + while (dialogCount()) + deleteDialog(0); if (fdir.cd("dialog")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -492,7 +501,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newDialog(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_eggGroups.clear(); + while (eggGroupCount()) + deleteEggGroup(0); if (fdir.cd("egggroup")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -500,7 +510,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newEggGroup(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_items.clear(); + while (itemCount()) + deleteItem(0); if (fdir.cd("item")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -508,7 +519,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newItem(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_itemTypes.clear(); + while (itemTypeCount()) + deleteItemType(0); if (fdir.cd("itemtype")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -516,7 +528,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newItemType(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_maps.clear(); + while (mapCount()) + deleteMap(0); if (fdir.cd("map")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -524,7 +537,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newMap(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_moves.clear(); + while (moveCount()) + deleteMove(0); if (fdir.cd("move")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -532,7 +546,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newMove(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_natures.clear(); + while (natureCount()) + deleteNature(0); if (fdir.cd("nature")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -540,7 +555,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newNature(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_species.clear(); + while (speciesCount()) + deleteSpecies(0); if (fdir.cd("m_species")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -548,7 +564,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newSpecies(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_stores.clear(); + while (storeCount()) + deleteStore(0); if (fdir.cd("store")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -556,7 +573,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newStore(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_tiles.clear(); + while (tileCount()) + deleteTile(0); if (fdir.cd("tile")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -564,7 +582,17 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newTile(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_trainers.clear(); + while (timeCount()) + deleteTime(0); + if (fdir.cd("time")) + { + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newTile(QString("%1/data.pini").arg(dir)); + fdir.cdUp(); + } + while (trainerCount()) + deleteTrainer(0); if (fdir.cd("trainer")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -572,7 +600,8 @@ void Pokemod::load(const QString& fileName, const int) throw(Exception) newTrainer(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - m_types.clear(); + while (typeCount()) + deleteType(0); if (fdir.cd("type")) { QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); @@ -2238,49 +2267,72 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs) m_superPCPasswd = rhs.m_superPCPasswd; m_typeChart = rhs.m_typeChart; m_rules = rhs.m_rules; - m_abilities.clear(); + while (abilityCount()) + deleteAbility(0); foreach (Ability* ability, rhs.m_abilities) m_abilities.append(new Ability(this, *ability, ability->id())); - m_authors.clear(); + while (authorCount()) + deleteAuthor(0); foreach (Author* author, rhs.m_authors) m_authors.append(new Author(this, *author, author->id())); - m_badges.clear(); + while (badgeCount()) + deleteBadge(0); foreach (Badge* badge, rhs.m_badges) m_badges.append(new Badge(this, *badge, badge->id())); - m_coinLists.clear(); + while (coinListCount()) + deleteCoinList(0); foreach (CoinList* coinList, rhs.m_coinLists) m_coinLists.append(new CoinList(this, *coinList, coinList->id())); - m_dialogs.clear(); + while (dialogCount()) + deleteDialog(0); foreach (Dialog* dialog, rhs.m_dialogs) m_dialogs.append(new Dialog(this, *dialog, dialog->id())); - m_eggGroups.clear(); + while (eggGroupCount()) + deleteEggGroup(0); foreach (EggGroup* eggGroup, rhs.m_eggGroups) m_eggGroups.append(new EggGroup(this, *eggGroup, eggGroup->id())); - m_items.clear(); + while (itemCount()) + deleteItem(0); foreach (Item* item, rhs.m_items) m_items.append(new Item(this, *item, item->id())); - m_itemTypes.clear(); + while (itemTypeCount()) + deleteItemType(0); foreach (ItemType* itemType, rhs.m_itemTypes) m_itemTypes.append(new ItemType(this, *itemType, itemType->id())); - m_maps.clear(); + while (mapCount()) + deleteMap(0); foreach (Map* map, rhs.m_maps) m_maps.append(new Map(this, *map, map->id())); - m_species.clear(); + while (moveCount()) + deleteMove(0); + foreach (Move* move, rhs.m_moves) + m_moves.append(new Move(this, *move, move->id())); + while (natureCount()) + deleteNature(0); + foreach (Nature* nature, rhs.m_natures) + m_natures.append(new Nature(this, *nature, nature->id())); + while (speciesCount()) + deleteSpecies(0); foreach (Species* species, rhs.m_species) m_species.append(new Species(this, *species, species->id())); - m_stores.clear(); + while (storeCount()) + deleteStore(0); foreach (Store* store, rhs.m_stores) m_stores.append(new Store(this, *store, store->id())); - m_tiles.clear(); + while (tileCount()) + deleteTile(0); foreach (Tile* tile, rhs.m_tiles) m_tiles.append(new Tile(this, *tile, tile->id())); - m_times.clear(); + while (timeCount()) + deleteTime(0); foreach (Time* time, rhs.m_times) m_times.append(new Time(this, *time, time->id())); - m_trainers.clear(); + while (trainerCount()) + deleteTrainer(0); foreach (Trainer* trainer, rhs.m_trainers) m_trainers.append(new Trainer(this, *trainer, trainer->id())); - m_types.clear(); + while (typeCount()) + deleteType(0); foreach (Type* type, rhs.m_types) m_types.append(new Type(this, *type, type->id())); return *this; |
