summaryrefslogtreecommitdiff
path: root/src/common/ers.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-03-16 13:49:06 -0300
committershennetsind <ind@henn.et>2014-03-16 13:49:06 -0300
commit2656f7f4026708f210c6ce7c39f5fc6831597982 (patch)
tree1dd5ee1a8152982b32ae8db4a6a2b01310f2d9c0 /src/common/ers.c
parent8c6547a5c3ec4d6b1845b60d14b0aae5c827892c (diff)
downloadhercules-2656f7f4026708f210c6ce7c39f5fc6831597982.tar.gz
hercules-2656f7f4026708f210c6ce7c39f5fc6831597982.tar.bz2
hercules-2656f7f4026708f210c6ce7c39f5fc6831597982.tar.xz
hercules-2656f7f4026708f210c6ce7c39f5fc6831597982.zip
Improved ERS memory handling
On shutdown the ERS will loop thru leftover managers and clear them according to each manager's settings, while also printing errors according to each manager's settings. Will also help pinpoint the causes of http://hercules.ws/board/tracker/issue-8093-memory-leak-after-stop-server-cant-fix/ and similar issues. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common/ers.c')
-rw-r--r--src/common/ers.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/common/ers.c b/src/common/ers.c
index eb351a988..5a3d7314a 100644
--- a/src/common/ers.c
+++ b/src/common/ers.c
@@ -115,17 +115,14 @@ struct ers_instance_t {
#ifdef DEBUG
/* for data analysis [Ind/Hercules] */
unsigned int Peak;
- struct ers_instance_t *Next, *Prev;
#endif
-
+ struct ers_instance_t *Next, *Prev;
};
// Array containing a pointer for all ers_cache structures
static ers_cache_t *CacheList = NULL;
-#ifdef DEBUG
- static struct ers_instance_t *InstanceList = NULL;
-#endif
+static struct ers_instance_t *InstanceList = NULL;
/**
* @param Options the options from the instance seeking a cache, we use it to give it a cache with matching configuration
@@ -180,6 +177,7 @@ static void ers_free_cache(ers_cache_t *cache, bool remove)
CacheList = cache->Next;
aFree(cache->Blocks);
+
aFree(cache);
}
@@ -285,7 +283,6 @@ static void ers_obj_destroy(ERS self)
if (--instance->Cache->ReferenceCount <= 0)
ers_free_cache(instance->Cache, true);
-#ifdef DEBUG
if (instance->Next)
instance->Next->Prev = instance->Prev;
@@ -293,7 +290,6 @@ static void ers_obj_destroy(ERS self)
instance->Prev->Next = instance->Next;
else
InstanceList = instance->Next;
-#endif
if( instance->Options & ERS_OPT_FREE_NAME )
aFree(instance->Name);
@@ -335,7 +331,7 @@ ERS ers_new(uint32 size, char *name, enum ERSOptions options)
instance->Cache = ers_find_cache(size,instance->Options);
instance->Cache->ReferenceCount++;
-#ifdef DEBUG
+
if (InstanceList == NULL) {
InstanceList = instance;
} else {
@@ -344,7 +340,6 @@ ERS ers_new(uint32 size, char *name, enum ERSOptions options)
InstanceList = instance;
InstanceList->Prev = NULL;
}
-#endif
instance->Count = 0;
@@ -392,12 +387,17 @@ void ers_report(void) {
ShowInfo("ers_report: '"CL_WHITE"%u"CL_NORMAL"' blocks total, consuming '"CL_WHITE"%.2f MB"CL_NORMAL"' \n",blocks_a,(double)((memory_t)/1024)/1024);
}
-void ers_force_destroy_all(void)
-{
- ers_cache_t *cache;
+/**
+ * Call on shutdown to clear remaining entries
+ **/
+void ers_final(void) {
+ struct ers_instance_t *instance = InstanceList, *next;
- for (cache = CacheList; cache; cache = cache->Next)
- ers_free_cache(cache, false);
+ while( instance ) {
+ next = instance->Next;
+ ers_obj_destroy((ERS)instance);
+ instance = next;
+ }
}
#endif