[+] Added uOldLength to the free function pointer type of the memory leak detection interface

This commit is contained in:
Reece Wilson 2024-01-17 20:55:59 +00:00
parent d4eab8e477
commit fce755f293
3 changed files with 22 additions and 18 deletions

View File

@ -12,7 +12,7 @@
namespace Aurora::Memory namespace Aurora::Memory
{ {
using LeakFinderAlloc_f = void(__cdecl *)(void *, AuUInt); using LeakFinderAlloc_f = void(__cdecl *)(void *, AuUInt);
using LeakFinderFree_f = void(__cdecl *)(void *); using LeakFinderFree_f = void(__cdecl *)(void *, AuUInt);
using MemoryLowNotification_f = void(__cdecl *)(AuUInt, int); using MemoryLowNotification_f = void(__cdecl *)(AuUInt, int);
} }

View File

@ -138,7 +138,7 @@ namespace Aurora::Memory
this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated); this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated);
if (this->pAlloc) if (this->pAlloc)
{ {
this->pFree(pHead); this->pFree(pHead, uLengthCurrent);
this->pAlloc(pThat, uLength); this->pAlloc(pThat, uLength);
} }
return pThat; return pThat;
@ -169,7 +169,7 @@ namespace Aurora::Memory
this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated); this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated);
if (this->pAlloc) if (this->pAlloc)
{ {
this->pFree(pHead); this->pFree(pHead, uLengthCurrent);
this->pAlloc(pThat, uLength); this->pAlloc(pThat, uLength);
} }
return pThat; return pThat;
@ -200,7 +200,7 @@ namespace Aurora::Memory
this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated); this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated);
if (this->pAlloc) if (this->pAlloc)
{ {
this->pFree(pHead); this->pFree(pHead, uLengthCurrent);
this->pAlloc(pThat, uLength); this->pAlloc(pThat, uLength);
} }
return pThat; return pThat;
@ -231,7 +231,7 @@ namespace Aurora::Memory
this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated); this->uBytesPeak = AuMax(this->uBytesPeak, this->uBytesAllocated);
if (this->pAlloc) if (this->pAlloc)
{ {
this->pFree(pHead); this->pFree(pHead, uLengthCurrent);
this->pAlloc(pThat, uLength); this->pAlloc(pThat, uLength);
} }
return pThat; return pThat;
@ -256,7 +256,7 @@ namespace Aurora::Memory
AuAtomicSub(&this->uBytesAllocated, uLengthCurrent); AuAtomicSub(&this->uBytesAllocated, uLengthCurrent);
if (this->pAlloc) if (this->pAlloc)
{ {
this->pFree(pHead); this->pFree(pHead, uLengthCurrent);
} }
} }
} }

View File

@ -100,11 +100,12 @@ namespace Aurora::Memory
} \ } \
else \ else \
{ \ { \
auto uCount = ::mi_malloc_size(pRet); \
if (gLeakFinderAlloc) \ if (gLeakFinderAlloc) \
{ \ { \
gLeakFinderAlloc(pRet, ::mi_malloc_size(pRet)); \ gLeakFinderAlloc(pRet, uCount); \
} \ } \
AddBytesToCounter(::mi_malloc_size(pRet)); \ AddBytesToCounter(uCount); \
} \ } \
return pRet; return pRet;
@ -158,7 +159,7 @@ namespace Aurora::Memory
{ {
if (gLeakFinderFree) if (gLeakFinderFree)
{ {
gLeakFinderFree(buffer); gLeakFinderFree(buffer, oldLen);
} }
gLeakFinderAlloc(pRet, uNewSize); gLeakFinderAlloc(pRet, uNewSize);
@ -203,7 +204,7 @@ namespace Aurora::Memory
{ {
if (gLeakFinderFree) if (gLeakFinderFree)
{ {
gLeakFinderFree(buffer); gLeakFinderFree(buffer, oldLen);
} }
gLeakFinderAlloc(pRet, uNewSize); gLeakFinderAlloc(pRet, uNewSize);
@ -248,7 +249,7 @@ namespace Aurora::Memory
{ {
if (gLeakFinderFree) if (gLeakFinderFree)
{ {
gLeakFinderFree(buffer); gLeakFinderFree(buffer, oldLen);
} }
gLeakFinderAlloc(pRet, uNewSize); gLeakFinderAlloc(pRet, uNewSize);
@ -293,7 +294,7 @@ namespace Aurora::Memory
{ {
if (gLeakFinderFree) if (gLeakFinderFree)
{ {
gLeakFinderFree(buffer); gLeakFinderFree(buffer, oldLen);
} }
gLeakFinderAlloc(pRet, uNewSize); gLeakFinderAlloc(pRet, uNewSize);
@ -325,13 +326,16 @@ namespace Aurora::Memory
} }
else else
{ {
RemoveBytesFromCounter(::mi_malloc_size(pHead)); auto uCount = ::mi_malloc_size(pHead);
::mi_free(pHead);
}
if (gLeakFinderFree) RemoveBytesFromCounter(uCount);
{ ::mi_free(pHead);
gLeakFinderFree(pHead);
if (gLeakFinderFree)
{
gLeakFinderFree(pHead, uCount);
}
} }
} }