Palm OS Memory Leak Detection
by Jeff Ishaq 

Example 1:

#define MemHandleNew(x) _DbgMemHandleNew( x, __FILE__, __LINE__ )
#define MemPtrNew(x)    _DbgMemPtrNew   ( x, __FILE__, __LINE__ )


Example 2:

gpOldMemHandleFree = (myMemHandleFreePtr) 
                      SysGetTrapAddress( sysTrapMemHandleFree );
SysSetTrapAddress( sysTrapMemHandleFree, _DbgMemHandleFree );

gpOldMemChunkFreePtr = (myMemChunkFreePtr) 
                        SysGetTrapAddress( sysTrapMemChunkFree );
SysSetTrapAddress( sysTrapMemChunkFree, _DbgMemChunkFree );


Example 3: 

(a)
#define new new( __FILE__, __LINE__ )

(b)
VoidPtr operator new( UInt32 size, CharPtr pFileName, ULong lineNum );
VoidPtr operator new[] ( UInt32 size, CharPtr pFileName, ULong lineNum );

(c)

VoidPtr operator new( UInt32 size, CharPtr pFileName, ULong lineNum )
{
   return _DbgMemPtrNew( size, pFileName, lineNum );
}
VoidPtr operator new [] ( UInt32 size, CharPtr pFileName, ULong lineNum )
{
   return _DbgMemPtrNew( size, pFileName, lineNum );
}


Listing One
// Each node knows if it came from MemHandleNew or MemPtrNew:
typedef enum tageAllocationType { PointerType, HandleType } eAllocationType;

typedef struct tagNode
{
   Char            fileName[MemDbgFilenameSize+1];
   ULong           lineNum,
                   size;
   eAllocationType type;
   union
   {
      VoidPtr      pAddr;
      VoidHand     hAddr;
   };
} Node;




1

