Add file and line number to debug version of realloc and free.

This commit is contained in:
ehouse 2007-11-22 05:04:40 +00:00
parent 022317b47a
commit 6e71f8197e
3 changed files with 20 additions and 10 deletions

View file

@ -162,8 +162,8 @@ typedef struct CommonPrefs {
#ifdef MEM_DEBUG
# define XP_MALLOC(pool,nbytes) \
mpool_alloc((pool),(nbytes),__FILE__,__LINE__)
# define XP_REALLOC(pool,p,s) mpool_realloc((pool),(p),(s))
# define XP_FREE(pool,p) mpool_free((pool), (p))
# define XP_REALLOC(pool,p,s) mpool_realloc((pool),(p),(s),__FILE__,__LINE__)
# define XP_FREE(pool,p) mpool_free((pool), (p),__FILE__,__LINE__)
# define MPFORMAL_NOCOMMA MemPoolCtx* mpool
# define MPFORMAL MPFORMAL_NOCOMMA,

View file

@ -165,29 +165,38 @@ findEntryFor( MemPoolCtx* mpool, void* ptr, MemPoolEntry** prevP )
return entry;
}
}
XP_ASSERT(0);
return (MemPoolEntry*)NULL;
} /* findEntryFor */
void*
mpool_realloc( MemPoolCtx* mpool, void* ptr, XP_U32 newsize )
mpool_realloc( MemPoolCtx* mpool, void* ptr, XP_U32 newsize, const char* file, XP_U32 lineNo )
{
MemPoolEntry* entry = findEntryFor( mpool, ptr, (MemPoolEntry**)NULL );
entry->ptr = XP_PLATREALLOC( entry->ptr, newsize );
XP_ASSERT( !!entry->ptr );
if ( !entry ) {
XP_LOGF( "findEntryFor failed; called from %s, line %d",
file, lineNo );
} else {
entry->ptr = XP_PLATREALLOC( entry->ptr, newsize );
XP_ASSERT( !!entry->ptr );
entry->fileName = file;
entry->lineNo = lineNo;
}
return entry->ptr;
} /* mpool_realloc */
void
mpool_free( MemPoolCtx* mpool, void* ptr )
mpool_free( MemPoolCtx* mpool, void* ptr, const char* file, XP_U32 lineNo )
{
MemPoolEntry* entry;
MemPoolEntry* prev;
entry = findEntryFor( mpool, ptr, &prev );
if ( !!entry ) {
if ( !entry ) {
XP_LOGF( "findEntryFor failed; called from %s, line %d",
file, lineNo );
} else {
if ( !!prev ) {
prev->next = entry->next;

View file

@ -35,8 +35,9 @@ void mpool_destroy( MemPoolCtx* mpool );
void* mpool_alloc( MemPoolCtx* mpool, XP_U32 size,
const char* file, XP_U32 lineNo );
void* mpool_realloc( MemPoolCtx* mpool, void* ptr, XP_U32 newsize );
void mpool_free( MemPoolCtx* mpool, void* ptr );
void* mpool_realloc( MemPoolCtx* mpool, void* ptr, XP_U32 newsize,
const char* file, XP_U32 lineNo );
void mpool_free( MemPoolCtx* mpool, void* ptr, const char* file, XP_U32 lineNo );
void mpool_stats( MemPoolCtx* mpool, XWStreamCtxt* stream );
XP_U16 mpool_getNUsed( MemPoolCtx* mpool );