summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-30 21:15:34 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-30 21:27:57 +0300
commitfce58131916103f3c2120adafcf59895a402a634 (patch)
treeaa2cebb167d7c6ffb90a71a631132779597bf2d4 /src
parent3e22726df1aecf9db96b558c9e7597166d685ad2 (diff)
downloadmv-fce58131916103f3c2120adafcf59895a402a634.tar.gz
mv-fce58131916103f3c2120adafcf59895a402a634.tar.bz2
mv-fce58131916103f3c2120adafcf59895a402a634.tar.xz
mv-fce58131916103f3c2120adafcf59895a402a634.zip
Extend leak detection features.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/commandhandler.cpp4
-rw-r--r--src/localconsts.h1
-rw-r--r--src/main.h1
-rw-r--r--src/playerinfo.cpp1
-rw-r--r--src/resources/resourcemanager.cpp40
-rw-r--r--src/resources/resourcemanager.h2
7 files changed, 41 insertions, 10 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b4010db58..8eac3d495 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,7 @@ manaplus_CXXFLAGS += -DENABLE_PORTABLE
endif
if ENABLE_MEM_DEBUG
-manaplus_CXXFLAGS += -DENABLE_MEM_DEBUG
+manaplus_CXXFLAGS += -DENABLE_MEM_DEBUG -DDEBUG_DUMP_LEAKS
manaplus_SOURCES = debug/debug_new.cpp \
debug/debug_new.h \
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 1afc332cb..8ed68ae20 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -61,7 +61,7 @@
#include "openglgraphics.h"
#endif
-#ifdef DEBUG_DUMP_LEAKS
+#ifdef DEBUG_DUMP_LEAKS1
#include "resources/image.h"
#include "resources/resource.h"
#include "resources/resourcemanager.h"
@@ -1212,7 +1212,7 @@ void CommandHandler::handleError(const std::string &args A_UNUSED,
logger->log("test %d", *ptr);
}
-#ifdef DEBUG_DUMP_LEAKS
+#ifdef DEBUG_DUMP_LEAKS1
void showRes(std::string str, ResourceManager::Resources *res);
void showRes(std::string str, ResourceManager::Resources *res)
diff --git a/src/localconsts.h b/src/localconsts.h
index 9f2454ba2..b01718d92 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -35,3 +35,4 @@
//#define DEBUG_CONFIG 1
//#define DEBUG_BIND_TEXTURE 1
//#define DISABLE_RESOURCE_CACHING 1
+#define DUMP_LEAKED_RESOURCES 1
diff --git a/src/main.h b/src/main.h
index 583079875..f3feec1ff 100644
--- a/src/main.h
+++ b/src/main.h
@@ -81,7 +81,6 @@
#define ENABLEDEBUGLOG 1
//define DEBUG_LEAKS 1
-//define DEBUG_DUMP_LEAKS 1
//define DEBUG_CONFIG 1
//define DEBUG_FONT 1
//define DEBUG_FONT_COUNTERS 1
diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp
index 2500e298e..eaf6e1350 100644
--- a/src/playerinfo.cpp
+++ b/src/playerinfo.cpp
@@ -357,6 +357,7 @@ void init()
void deinit()
{
+ clearInventory();
delete mListener;
mListener = nullptr;
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 9b5394687..452bc9942 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -177,9 +177,12 @@ void ResourceManager::cleanUp(Resource *res)
}
delete res;
+#ifdef DEBUG_LEAKS
+ cleanOrpahns(true);
+#endif
}
-void ResourceManager::cleanOrphans(bool always)
+bool ResourceManager::cleanOrphans(bool always)
{
timeval tv;
gettimeofday(&tv, nullptr);
@@ -187,8 +190,10 @@ void ResourceManager::cleanOrphans(bool always)
time_t oldest = tv.tv_sec, threshold = oldest - 30;
if (mOrphanedResources.empty() || (!always && mOldestOrphan >= threshold))
- return;
+ return false;
+ bool status(false);
+ status = false;
ResourceIterator iter = mOrphanedResources.begin();
while (iter != mOrphanedResources.end())
{
@@ -199,10 +204,11 @@ void ResourceManager::cleanOrphans(bool always)
continue;
}
time_t t = res->mTimeStamp;
- if (t >= threshold)
+ if (!always && t >= threshold)
{
- if (t < oldest) oldest = t;
- ++iter;
+ if (t < oldest)
+ oldest = t;
+ ++ iter;
}
else
{
@@ -212,10 +218,12 @@ void ResourceManager::cleanOrphans(bool always)
mOrphanedResources.erase(toErase);
delete res; // delete only after removal from list,
// to avoid issues in recursion
+ status = true;
}
}
mOldestOrphan = oldest;
+ return status;
}
bool ResourceManager::setWriteDir(const std::string &path)
@@ -602,6 +610,28 @@ ResourceManager *ResourceManager::getInstance()
void ResourceManager::deleteInstance()
{
+#ifdef DUMP_LEAKED_RESOURCES
+ if (instance)
+ {
+ logger->log("clean orphans start");
+ while(instance->cleanOrphans(true));
+ logger->log("clean orphans end");
+ ResourceIterator iter = instance->mResources.begin();
+
+ while (iter != instance->mResources.end())
+ {
+ if (iter->second)
+ {
+ if (iter->second->getRefCount())
+ {
+ logger->log("ResourceLeak: " + iter->second->getIdPath()
+ + " (" + toString(iter->second->getRefCount()) + ")");
+ }
+ }
+ ++iter;
+ }
+ }
+#endif
delete instance;
instance = nullptr;
}
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 0eadf683d..b07b23431 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -276,7 +276,7 @@ class ResourceManager
{ return &mOrphanedResources; }
#endif
- void cleanOrphans(bool always = false);
+ bool cleanOrphans(bool always = false);
static void addDelayedAnimation(AnimationDelayLoad *animation)
{ mDelayedAnimations.push_back(animation); }