diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-08-29 21:47:06 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-08-29 21:47:06 +0300 |
commit | ede06c1fe25184b1232687950ce79dc29352c00b (patch) | |
tree | bb8e20aa562e845e4846fa76166b8ac3c6e2f9d3 | |
parent | 9ff7894ef1eeff001f3ddc1a1caec18176428fa1 (diff) | |
download | manaplus-ede06c1fe25184b1232687950ce79dc29352c00b.tar.gz manaplus-ede06c1fe25184b1232687950ce79dc29352c00b.tar.bz2 manaplus-ede06c1fe25184b1232687950ce79dc29352c00b.tar.xz manaplus-ede06c1fe25184b1232687950ce79dc29352c00b.zip |
Add into resource manager better reports about leaks.
-rw-r--r-- | src/resources/resourcemanager/resourcemanager.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp index 5ecc58732..b4e80d2c1 100644 --- a/src/resources/resourcemanager/resourcemanager.cpp +++ b/src/resources/resourcemanager/resourcemanager.cpp @@ -69,6 +69,7 @@ ResourceManager::~ResourceManager() ResourceIterator iter = mResources.begin(); #ifdef DEBUG_LEAKS + bool status(false); while (iter != mResources.end()) { if (iter->second) @@ -78,11 +79,17 @@ ResourceManager::~ResourceManager() logger->log(std::string("ResourceLeak: ").append( iter->second->getIdPath()).append(" (").append( toString(iter->second->getRefCount())).append(")")); + status = true; } } ++iter; } +#ifdef UNITTESTS + if (status) + reportAlways("Found leaked resources."); +#endif + iter = mResources.begin(); #endif @@ -269,7 +276,11 @@ void ResourceManager::logResource(const Resource *const res) } else { - logger->log("resource(%s)", res->mIdPath.c_str()); + std::string src = res->getSource(); + const int count = res->getRefCount(); + if (count > 0) + src.append(" ").append(toString(count)); + logger->log("resource(%s) %s", res->mIdPath.c_str(), src.c_str()); } #else logger->log("resource(%s)", res->mIdPath.c_str()); @@ -631,6 +642,7 @@ void ResourceManager::deleteInstance() logger->log1("clean orphans end"); ResourceIterator iter = resourceManager->mResources.begin(); + bool status(false); while (iter != resourceManager->mResources.end()) { const Resource *const res = iter->second; @@ -641,10 +653,15 @@ void ResourceManager::deleteInstance() logger->log(std::string("ResourceLeak: ").append( res->getIdPath()).append(" (").append(toString( res->getRefCount())).append(")")); + status = true; } } ++iter; } +#ifdef UNITTESTS + if (status) + reportAlways("Found leaked resources."); +#endif } #endif delete2(resourceManager); |