diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-01-05 18:42:01 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-01-05 18:42:01 +0300 |
commit | 62e4add49caa9b2a3a89fe3ab463d9d8a62344c8 (patch) | |
tree | fe3847b3362a99a9d47459f87af20f5b04bca101 /src | |
parent | f2d1d2b43a0ebdb625aea94cb4b8ff7fce6bf8f4 (diff) | |
download | manaplus-62e4add49caa9b2a3a89fe3ab463d9d8a62344c8.tar.gz manaplus-62e4add49caa9b2a3a89fe3ab463d9d8a62344c8.tar.bz2 manaplus-62e4add49caa9b2a3a89fe3ab463d9d8a62344c8.tar.xz manaplus-62e4add49caa9b2a3a89fe3ab463d9d8a62344c8.zip |
dont leak memory if exists item duplicates with same id.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/db/itemdb.cpp | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 4c702ed33..de422cd95 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -237,6 +237,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) continue; const int id = XML::getProperty(node, "id", 0); + ItemInfo *itemInfo = nullptr; if (id == 0) { @@ -247,7 +248,10 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) else if (mItemInfos.find(id) != mItemInfos.end()) { logger->log("ItemDB: Redefinition of item ID %d", id); + itemInfo = mItemInfos[id]; } + if (!itemInfo) + itemInfo = new ItemInfo; const std::string typeStr = XML::getProperty(node, "type", "other"); const int weight = XML::getProperty(node, "weight", 0); @@ -310,7 +314,6 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) else display.floor = image; - ItemInfo *const itemInfo = new ItemInfo; itemInfo->setId(id); // TRANSLATORS: item info name itemInfo->setName(name.empty() ? _("unnamed") : name); @@ -485,18 +488,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) if (!name.empty()) { temp = normalize(name); - - const NamedItemInfos::const_iterator - itr = mNamedItemInfos.find(temp); - if (itr == mNamedItemInfos.end()) - { - mNamedItemInfos[temp] = itemInfo; - } - else - { - logger->log("ItemDB: Duplicate name of item found item %d", - id); - } + mNamedItemInfos[temp] = itemInfo; } if (!attackAction.empty()) |