From 62e4add49caa9b2a3a89fe3ab463d9d8a62344c8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 5 Jan 2014 18:42:01 +0300 Subject: dont leak memory if exists item duplicates with same id. --- src/resources/db/itemdb.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/resources') 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()) -- cgit v1.2.3-70-g09d2