From e5de543efb891e6feb190a85103b1e53406e29c7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 7 Jan 2014 16:03:25 +0300 Subject: fix leak in petdb with duplicate pets. --- src/resources/db/petdb.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp index aef1b2bda..0529ee874 100644 --- a/src/resources/db/petdb.cpp +++ b/src/resources/db/petdb.cpp @@ -80,15 +80,19 @@ void PETDB::loadXmlFile(const std::string &fileName) continue; } - const int id = XML::getProperty(petNode, "id", 0); - if (id == 0) + const int id = XML::getProperty(petNode, "id", -1); + if (id == -1) { logger->log("PET Database: PET with missing ID in %s!", paths.getStringValue("petsFile").c_str()); continue; } - BeingInfo *const currentInfo = new BeingInfo; + BeingInfo *currentInfo = nullptr; + if (mPETInfos.find(id) != mPETInfos.end()) + currentInfo = mPETInfos[id]; + if (!currentInfo) + currentInfo = new BeingInfo; currentInfo->setName(XML::langProperty(petNode, // TRANSLATORS: unknown info name -- cgit v1.2.3-60-g2f50