vPortFree() Hangs due to Assertion Failure
I have difficulty with the below code which I have paired down to it’s essentials:
- define malloc(size) pvPortMalloc(size)
- define free(ptr) vPortFree(ptr)
typedef uint8_t Msg_Itr_t;
typedef struct
{ Msg_Itr_t itr;
int32_t strln;
char *pstr;
} Msg_t;
typedef Msg_t* pMsg_t;
pMsg_t pEchoMsg;
pEchoMsg = malloc( sizeof( pMsg_t ) );
if( pEchoMsg )
{ pEchoMsg->pstr = malloc( sizeof( uint8_t ) );
if( pEchoMsg->pstr )
{ free( pEchoMsg->pstr ); // Hangs here
}
free( pEchoMsg );
}
Please note that I have redefined malloc() and free() with the macros included in the above code.
On the call to the first free() it hangs because in vPortFree() the below assertion fails, causing it to go into an infinite loop:
configASSERT( pxLink->pxNextFreeBlock == NULL );
If I free pEchoMsg right after it is allocated it works. But if I free the allocation pointed within pEchoMsg as shown in the code above it fails. What is going wrong here?