diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-01-06 12:33:48 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-01-06 12:33:48 +0300 |
commit | 5ab85579f493e951d0042cd879cc848d4c7c871b (patch) | |
tree | 1d68b7936d5bf360d59c2c54b9c8e9b61e99c928 | |
parent | 2e5ea73d5f0792863a1093de7daf21092b233d98 (diff) | |
download | manaverse-5ab85579f493e951d0042cd879cc848d4c7c871b.tar.gz manaverse-5ab85579f493e951d0042cd879cc848d4c7c871b.tar.bz2 manaverse-5ab85579f493e951d0042cd879cc848d4c7c871b.tar.xz manaverse-5ab85579f493e951d0042cd879cc848d4c7c871b.zip |
dont leak memory if exists monster duplicate with same id.
-rw-r--r-- | src/resources/db/monsterdb.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp index f1c1a73d7..f04743507 100644 --- a/src/resources/db/monsterdb.cpp +++ b/src/resources/db/monsterdb.cpp @@ -88,7 +88,21 @@ void MonsterDB::loadXmlFile(const std::string &fileName) if (!xmlNameEqual(monsterNode, "monster")) continue; - BeingInfo *const currentInfo = new BeingInfo; + const int id = XML::getProperty(monsterNode, "id", 0); + BeingInfo *currentInfo = nullptr; + if (id == 0) + { + logger->log("MonsterDB: monster with missing ID in %s!", + fileName.c_str()); + continue; + } + else if (mMonsterInfos.find(id + offset) != mMonsterInfos.end()) + { + logger->log("MonsterDB: Redefinition of monster ID %d", id); + currentInfo = mMonsterInfos[id + offset]; + } + if (!currentInfo) + currentInfo = new BeingInfo; currentInfo->setWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER | Map::BLOCKMASK_MONSTER); @@ -234,8 +248,7 @@ void MonsterDB::loadXmlFile(const std::string &fileName) } currentInfo->setDisplay(display); - mMonsterInfos[XML::getProperty( - monsterNode, "id", 0) + offset] = currentInfo; + mMonsterInfos[id + offset] = currentInfo; } } |