From 2e5ea73d5f0792863a1093de7daf21092b233d98 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 6 Jan 2014 12:26:11 +0300 Subject: dont leak memory if exists npc duplicate with same id. --- src/resources/db/npcdb.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/resources/db/npcdb.cpp') 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)); -- cgit v1.2.3-70-g09d2