I will check out the differences. In the meantime I was going to add a big zip file of our cellular library test code. However, as a new user I cannot upload files. Here is the list of what we tried. The pointers all seem to line up but there is a difference when we “print the heap status”
#ifdef CONFIG_CDB_PLATFORM
#ifdef DEBUG_CHECK_MEMORY_LEAKS
static uint32_t platformFreeCount = 0;
static uint32_t platformMallocCount = 0;
/**
* Saved list of pointers
*/
#define NUMBER_OF_POINTERS_IN_LIST 2000
struct debugPointerEntry_t {
char type;
uint32_t tickCount;
uint32_t mfCount;
size_t sizeRequested;
uint32_t *address;
};
#define GET_TIME_MS (*((volatile uint32_t*)0X5074207C))
//uint32_t time_now = (GET_TIME_MS*31)/1000;
static uint32_t pointerListIdx = 0;
struct debugPointerEntry_t pointerTable[ NUMBER_OF_POINTERS_IN_LIST ];
void prvStoreDebugPointer( bool isMalloc, void *address, size_t sizeRequested );
void prvStoreDebugPointer( bool isMalloc, void *address, size_t sizeRequested )
{
if( pointerListIdx >= (sizeof pointerTable / sizeof pointerTable[0] ) ) return;
pointerTable[ pointerListIdx ].type = ( isMalloc ) ? 'm' : 'f' ;
pointerTable[ pointerListIdx ].mfCount = ( isMalloc ) ? platformMallocCount: platformFreeCount;
pointerTable[ pointerListIdx ].sizeRequested = sizeRequested;
pointerTable[ pointerListIdx ].tickCount = (GET_TIME_MS*31)/1000;
pointerTable[ pointerListIdx ].address = address;
pointerListIdx++;
}
void printPointerTable( void );
void printPointerTable( void )
{
// Printing in sequence
for( uint32_t loopIdx = 0; loopIdx < pointerListIdx; loopIdx++ )
{
if( 'm' == pointerTable[ loopIdx ].type )
{
configPRINTF( ("\x1B[35mMALL-%p,size=%lu,tick=%lu\x1B[0m\r\n", pointerTable[ loopIdx ].address, pointerTable[ loopIdx ].sizeRequested, pointerTable[ loopIdx ].tickCount ) );
}
else
{
configPRINTF( ( "\x1B[45mFREE-%p,size=%lu,tick=%lu\x1B[0m\r\n", pointerTable[ loopIdx ].address, pointerTable[ loopIdx ].sizeRequested, pointerTable[ loopIdx ].tickCount ) );
}
}
}
#endif /* DEBUG_CHECK_MEMORY_LEAKS */
#endif /* CONFIG_CDB_PLATFORM */
/*-----------------------------------------------------------*/
/**
* Platform dependent abstraction helper layer
* With simple setup no extra abstraction is required, can rely on macro definition in header file
*/
#ifdef CONFIG_CDB_PLATFORM
#ifdef DEBUG_CHECK_MEMORY_LEAKS
extern QCLI_Group_Handle_t qcli_bg95_demo_handle; /* Handle for BG95 demo Command Group. */
// Implemented as a debug abstraction layer function
void * Platform_Malloc( size_t xWantedSize )
{
void *retPtr = NULL;
retPtr = malloc( xWantedSize );
prvStoreDebugPointer( true, retPtr, xWantedSize );
// CellularLogDebug( "\x1B[32m%s ptr=%p, size=%lu\x1B[0m", __func__, retPtr, xWantedSize );
// configPRINTF( ("\x1B[32m%s ptr=%p, size=%lu\x1B[0m\r\n", __func__, retPtr, xWantedSize) );
// QCLI_Printf( qcli_bg95_demo_handle, "\x1B[32m%s ptr=%p, size=%lu\x1B[0m", __func__, retPtr, xWantedSize );
platformMallocCount++;
return retPtr;
}
void Platform_Free( void * pv )
{
// CellularLogDebug( "\x1B[32m%s ptr=%p\x1B[0m", __func__, pv );
// configPRINTF( ("\x1B[32m%s ptr=%p\x1B[0m\r\n", __func__, pv) );
// QCLI_Printf( qcli_bg95_demo_handle, "\x1B[32m%s ptr=%p\x1B[0m", __func__, pv );
prvStoreDebugPointer( false, pv, 0 );
free( pv );
platformFreeCount++;
}
#else
// deliberately empty as macro defines this case
#endif /* DEBUG_CHECK_MEMORY_LEAKS */
#else
// deliberately empty as macro defines this case
#endif /* CONFIG_CDB_PLATFORM */