summaryrefslogtreecommitdiffstats
path: root/source/LeakFinder.cpp
diff options
context:
space:
mode:
authorkeyboard.osh@gmail.com <keyboard.osh@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-25 01:07:50 +0100
committerkeyboard.osh@gmail.com <keyboard.osh@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-25 01:07:50 +0100
commitbdc7d5f9c7f025f79499810e5e794821a011eae9 (patch)
tree2b0b6afa44aeeddff825a12d71c1880989bcc5e1 /source/LeakFinder.cpp
parentTweaked LeakFinder for VC2012 debug build (too much housekeeping info allocated) (diff)
downloadcuberite-bdc7d5f9c7f025f79499810e5e794821a011eae9.tar
cuberite-bdc7d5f9c7f025f79499810e5e794821a011eae9.tar.gz
cuberite-bdc7d5f9c7f025f79499810e5e794821a011eae9.tar.bz2
cuberite-bdc7d5f9c7f025f79499810e5e794821a011eae9.tar.lz
cuberite-bdc7d5f9c7f025f79499810e5e794821a011eae9.tar.xz
cuberite-bdc7d5f9c7f025f79499810e5e794821a011eae9.tar.zst
cuberite-bdc7d5f9c7f025f79499810e5e794821a011eae9.zip
Diffstat (limited to 'source/LeakFinder.cpp')
-rw-r--r--source/LeakFinder.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/source/LeakFinder.cpp b/source/LeakFinder.cpp
index d8d41883b..3242bba04 100644
--- a/source/LeakFinder.cpp
+++ b/source/LeakFinder.cpp
@@ -448,6 +448,7 @@ public:
}
pHashEntry->Next = (AllocHashEntryType*) own_malloc(sizeof(AllocHashEntryType));
+ g_CurrentMemUsage += CRTTable::AllocHashEntryTypeSize;
pHashEntry = pHashEntry->Next;
if (pHashEntry == NULL)
{
@@ -522,6 +523,7 @@ public:
AllocHashEntryType *pTmp = pHashEntry->Next;
*pHashEntry = *(pHashEntry->Next);
own_free(pTmp);
+ g_CurrentMemUsage -= CRTTable::AllocHashEntryTypeSize;
}
return TRUE;
}
@@ -529,6 +531,7 @@ public:
// now, I am in an dynamic allocated entry (it was a collision)
pHashEntryLast->Next = pHashEntry->Next;
own_free(pHashEntry);
+ g_CurrentMemUsage -= CRTTable::AllocHashEntryTypeSize;
return TRUE;
}
}
@@ -859,8 +862,24 @@ static int MyAllocHook(int nAllocType, void *pvData,
if (lRequest != 0)
{
// RequestID was found
- g_CurrentMemUsage -= nSize + CRTTable::AllocHashEntryTypeSize;
+ size_t temp = g_CurrentMemUsage;
+ g_CurrentMemUsage -= nSize ;
g_pCRTTable->Remove(lRequest);
+ if (g_CurrentMemUsage > temp)
+ {
+ printf("********************************************\n");
+ printf("** Server detected underflow in memory **\n");
+ printf("** usage counter. Something is not right. **\n");
+ printf("** Writing memory dump into memdump.xml **\n");
+ printf("********************************************\n");
+ printf("Please wait\n");
+
+ LeakFinderXmlOutput Output("memdump.xml");
+ DumpUsedMemory(&Output);
+
+ printf("\nMemory dump complete. Server will now abort.\n");
+ abort();
+ }
}
} // freeing
@@ -877,8 +896,24 @@ static int MyAllocHook(int nAllocType, void *pvData,
pHead = pHdr(pvData);
// Try to find the RequestID in the Hash-Table, mark it that it was freed
lReallocRequest = pHead->lRequest;
- g_CurrentMemUsage -= pHead->nDataSize + CRTTable::AllocHashEntryTypeSize;
+ size_t temp = g_CurrentMemUsage;
+ g_CurrentMemUsage -= pHead->nDataSize;
bRet = g_pCRTTable->Remove(lReallocRequest);
+ if (g_CurrentMemUsage > temp)
+ {
+ printf("********************************************\n");
+ printf("** Server detected underflow in memory **\n");
+ printf("** usage counter. Something is not right. **\n");
+ printf("** Writing memory dump into memdump.xml **\n");
+ printf("********************************************\n");
+ printf("Please wait\n");
+
+ LeakFinderXmlOutput Output("memdump.xml");
+ DumpUsedMemory(&Output);
+
+ printf("\nMemory dump complete. Server will now abort.\n");
+ abort();
+ }
} // ValidHeapPointer
} // re-allocating
@@ -902,9 +937,12 @@ static int MyAllocHook(int nAllocType, void *pvData,
{
if (lRequest != 0) // Always a valid RequestID should be provided (see comments in the header)
{
- g_CurrentMemUsage += nSize + CRTTable::AllocHashEntryTypeSize;
+ //No need to check for overflow since we are checking if we are getting higher than 1gb.
+ //If we change this, then we probably would want an overflow check.
+ g_CurrentMemUsage += nSize ;
+ g_pCRTTable->Insert(lRequest, c, nSize);
- if (g_CurrentMemUsage > 1024 * 1024 * 1024)
+ if (g_CurrentMemUsage > 1073741824) //This is 1 gb = 1024 * 1024* 1024.
{
printf("******************************************\n");
printf("** Server reached 1 GiB memory usage, **\n");
@@ -919,8 +957,6 @@ static int MyAllocHook(int nAllocType, void *pvData,
printf("\nMemory dump complete. Server will now abort.\n");
abort();
}
-
- g_pCRTTable->Insert(lRequest, c, nSize);
}
}