Issue #597 - Minor enhancement of memory debug in alloc.c

This commit is contained in:
Geoff McLane 2017-09-17 16:28:39 +02:00
parent 3e27882109
commit 5d017fe532

View file

@ -18,6 +18,13 @@ static TidyRealloc g_realloc = NULL;
static TidyFree g_free = NULL; static TidyFree g_free = NULL;
static TidyPanic g_panic = NULL; static TidyPanic g_panic = NULL;
#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY)
static int alloccnt = 0;
static int realloccnt = 0;
static int freecnt = 0;
#endif
Bool TIDY_CALL tidySetMallocCall( TidyMalloc fmalloc ) Bool TIDY_CALL tidySetMallocCall( TidyMalloc fmalloc )
{ {
g_malloc = fmalloc; g_malloc = fmalloc;
@ -60,7 +67,8 @@ static void* TIDY_CALL defaultAlloc( TidyAllocator* allocator, size_t size )
if ( !p ) if ( !p )
defaultPanic( allocator,"Out of memory!"); defaultPanic( allocator,"Out of memory!");
#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY) #if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY)
SPRTF("alloc MEM %p, size %d\n", p, (int)size ); alloccnt++;
SPRTF("%d: alloc MEM %p, size %d\n", alloccnt, p, (int)size );
if (size == 0) { if (size == 0) {
SPRTF("NOTE: An allocation of ZERO bytes!!!!!!\n"); SPRTF("NOTE: An allocation of ZERO bytes!!!!!!\n");
} }
@ -78,7 +86,8 @@ static void* TIDY_CALL defaultRealloc( TidyAllocator* allocator, void* mem, size
if (!p) if (!p)
defaultPanic( allocator, "Out of memory!"); defaultPanic( allocator, "Out of memory!");
#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY) #if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY)
SPRTF("realloc MEM %p, size %d\n", p, (int)newsize ); realloccnt++;
SPRTF("%d: realloc MEM %p, size %d\n", realloccnt, p, (int)newsize );
#endif #endif
return p; return p;
} }
@ -88,7 +97,8 @@ static void TIDY_CALL defaultFree( TidyAllocator* ARG_UNUSED(allocator), void* m
if ( mem ) if ( mem )
{ {
#if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY) #if !defined(NDEBUG) && defined(_MSC_VER) && defined(DEBUG_MEMORY)
SPRTF("free MEM %p\n", mem ); freecnt++;
SPRTF("%d: free MEM %p\n", freecnt, mem );
#endif #endif
if ( g_free ) if ( g_free )
g_free( mem ); g_free( mem );