mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
modify MEM_DEBUG versions of strdup utils to record the __FILE__ and
__LINE__ of callers rather than their own to assist in leak detection.
This commit is contained in:
parent
d06daad4f0
commit
d382431922
2 changed files with 48 additions and 7 deletions
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "strutils.h"
|
||||
#include "xwstream.h"
|
||||
#include "mempool.h"
|
||||
#include "xptypes.h"
|
||||
|
||||
#ifdef CPLUS
|
||||
extern "C" {
|
||||
|
@ -138,12 +140,21 @@ stringToStream( XWStreamCtxt* stream, XP_UCHAR* str )
|
|||
*
|
||||
****************************************************************************/
|
||||
XP_UCHAR*
|
||||
copyString( MPFORMAL const XP_UCHAR* instr )
|
||||
p_copyString( MPFORMAL const XP_UCHAR* instr
|
||||
#ifdef MEM_DEBUG
|
||||
, const char* file, XP_U32 lineNo
|
||||
#endif
|
||||
)
|
||||
{
|
||||
XP_UCHAR* result = (XP_UCHAR*)NULL;
|
||||
if ( !!instr ) {
|
||||
XP_U16 len = 1 + XP_STRLEN( (const char*)instr );
|
||||
result = (XP_UCHAR*)XP_MALLOC( (MemPoolCtx*)mpool, len );
|
||||
#ifdef MEM_DEBUG
|
||||
result = mpool_alloc( mpool, len, file, lineNo );
|
||||
#else
|
||||
result = XP_MALLOC( ignore, len );
|
||||
#endif
|
||||
|
||||
XP_ASSERT( !!result );
|
||||
XP_MEMCPY( result, instr, len );
|
||||
}
|
||||
|
@ -151,7 +162,11 @@ copyString( MPFORMAL const XP_UCHAR* instr )
|
|||
} /* copyString */
|
||||
|
||||
void
|
||||
replaceStringIfDifferent( MPFORMAL XP_UCHAR** curLoc, const XP_UCHAR* newStr )
|
||||
p_replaceStringIfDifferent( MPFORMAL XP_UCHAR** curLoc, const XP_UCHAR* newStr
|
||||
#ifdef MEM_DEBUG
|
||||
, const char* file, XP_U32 lineNo
|
||||
#endif
|
||||
)
|
||||
{
|
||||
XP_UCHAR* curStr = *curLoc;
|
||||
|
||||
|
@ -162,7 +177,11 @@ replaceStringIfDifferent( MPFORMAL XP_UCHAR** curLoc, const XP_UCHAR* newStr )
|
|||
if ( !!curStr ) {
|
||||
XP_FREE( mpool, curStr );
|
||||
}
|
||||
curStr = copyString( MPPARM(mpool) newStr );
|
||||
#ifdef MEM_DEBUG
|
||||
curStr = p_copyString( mpool, newStr, file, lineNo );
|
||||
#else
|
||||
curStr = p_copyString( newStr );
|
||||
#endif
|
||||
}
|
||||
|
||||
*curLoc = curStr;
|
||||
|
|
|
@ -41,9 +41,31 @@ XP_UCHAR* stringFromStream( MPFORMAL XWStreamCtxt* stream );
|
|||
XP_U16 stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 len );
|
||||
void stringToStream( XWStreamCtxt* stream, XP_UCHAR* str );
|
||||
|
||||
XP_UCHAR* copyString( MPFORMAL const XP_UCHAR* instr );
|
||||
void replaceStringIfDifferent( MPFORMAL XP_UCHAR** curLoc,
|
||||
const XP_UCHAR* newStr );
|
||||
XP_UCHAR* p_copyString( MPFORMAL const XP_UCHAR* instr
|
||||
#ifdef MEM_DEBUG
|
||||
, const char* file, XP_U32 lineNo
|
||||
#endif
|
||||
);
|
||||
#ifdef MEM_DEBUG
|
||||
# define copyString( p, in ) p_copyString( (p), (in), __FILE__, __LINE__ )
|
||||
#else
|
||||
# define copyString( p, in ) p_copyString( in )
|
||||
#endif
|
||||
|
||||
|
||||
void p_replaceStringIfDifferent( MPFORMAL XP_UCHAR** curLoc,
|
||||
const XP_UCHAR* newStr
|
||||
#ifdef MEM_DEBUG
|
||||
, const char* file, XP_U32 lineNo
|
||||
#endif
|
||||
);
|
||||
#ifdef MEM_DEBUG
|
||||
# define replaceStringIfDifferent(p, sp, n) \
|
||||
p_replaceStringIfDifferent( (p), (sp), (n), __FILE__, __LINE__ )
|
||||
#else
|
||||
# define replaceStringIfDifferent(p, sp, n) p_replaceStringIfDifferent((sp),(n))
|
||||
#endif
|
||||
|
||||
|
||||
XP_UCHAR* emptyStringIfNull( XP_UCHAR* str );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue