Hi Graham,
We do some test with the BG96 MQTT demo application and didn’t observe the memory leak.
The highwater mark is 2620 bytes. The allocated memory after Cellular_Cleanup is called is 0.
Below is how we setup the test.
Hook the Platform_Malloc and Platform_Free function with the following code snippet.
uint32_t mallocSize = 0;
uint32_t mallocHigh = 0;
/**
* Allocate extra memory to keep the allocated memory size informatioin.
* -------------------------------------
* | uint32_t size | allocated memory |
* -------------------------------------
*/
void * Platform_Malloc( size_t size )
{
void * ptr = NULL;
uint32_t * ptrU32 = NULL;
ptrU32 = pvPortMalloc( size + sizeof( uint32_t ) );
if( ptrU32 != NULL )
{
ptrU32[0] = size;
ptr = &ptrU32[1];
mallocSize = mallocSize + size;
if( mallocSize > mallocHigh )
{
mallocHigh = mallocSize;
}
}
return ptr;
}
/*-----------------------------------------------------------*/
/**
* Free the memory also decrease total allocated memory.
*/
void Platform_Free( void * ptr )
{
uint32_t * ptrU32 = NULL;
if( ptr != NULL )
{
ptrU32 = ptr;
ptrU32 = ptrU32 - 1;
mallocSize = mallocSize - ptrU32[ 0 ];
vPortFree( ptrU32 );
}
}
/*-----------------------------------------------------------*/
Update the cellularDemoTask with the following code.
#include "cellular_config.h"
#include "cellular_config_defaults.h"
#include "cellular_types.h"
#include "cellular_api.h"
extern mallocSize;
extern mallocHigh;
extern CellularHandle_t CellularHandle;
static void CellularDemoTask( void * pvParameters )
{
bool retCellular = true;
( void ) pvParameters;
while( true )
{
/* Setup cellular. */
retCellular = setupCellular();
/* Stop here if we fail to initialize cellular. */
configASSERT( retCellular == true );
/* Run the MQTT demo. */
LogInfo( ( "---------STARTING DEMO---------\r\n" ) );
/* Update the MQTT demo to run only 3 times then return. */
vStartSimpleMQTTDemo();
Cellular_Cleanup( CellularHandle );
LogInfo( ( "total malloc size %u high malloc %u\r\n", mallocSize, mallocHigh ) );
}
vTaskDelete( NULL );
}