summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-06 12:26:11 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-06 12:26:11 +0300
commit2e5ea73d5f0792863a1093de7daf21092b233d98 (patch)
tree20b3a541716285e5151670c1a2c906efda8a40b7
parent408da061e6098c6562f69b50d16353c7efc5cdf2 (diff)
downloadmanaverse-2e5ea73d5f0792863a1093de7daf21092b233d98.tar.gz
manaverse-2e5ea73d5f0792863a1093de7daf21092b233d98.tar.bz2
manaverse-2e5ea73d5f0792863a1093de7daf21092b233d98.tar.xz
manaverse-2e5ea73d5f0792863a1093de7daf21092b233d98.zip
dont leak memory if exists npc duplicate with same id.
-rw-r--r--src/resources/db/npcdb.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp
index 486f63952..7c983160c 100644
--- a/src/resources/db/npcdb.cpp
+++ b/src/resources/db/npcdb.cpp
@@ -80,14 +80,20 @@ void NPCDB::loadXmlFile(const std::string &fileName)
continue;
const int id = XML::getProperty(npcNode, "id", 0);
+ BeingInfo *currentInfo = nullptr;
if (id == 0)
{
logger->log("NPC Database: NPC with missing ID in %s!",
paths.getStringValue("npcsFile").c_str());
continue;
}
-
- BeingInfo *const currentInfo = new BeingInfo;
+ else if (mNPCInfos.find(id) != mNPCInfos.end())
+ {
+ logger->log("NpcDB: Redefinition of npc ID %d", id);
+ currentInfo = mNPCInfos[id];
+ }
+ if (!currentInfo)
+ currentInfo = new BeingInfo;
currentInfo->setTargetSelection(XML::getBoolProperty(npcNode,
"targetSelection", true));