Hi, I'm using arm cortex, KEIL, FreeRTOS. The problem I met is: after many times of running the following malloc function, the heap was used out, couldn't allocat 1KB space any more.
char Str = (char )myMalloc(strLen); // strLen is a variable, value between 0 and 1024 if(Str != NULL){ ...... myFree(Str); }
Here are the definitions of myMalloc and myFree:
void myMalloc( size_t xWantedSize ) { void pvReturn;
pvReturn = NULL; if(xWantedSize) { vTaskSuspendAll(); pvReturn = malloc( xWantedSize ); xTaskResumeAll(); } return pvReturn; } void myFree( void *pv ) { if( pv ){ vTaskSuspendAll(); free( pv ); xTaskResumeAll(); } }
After the parameter strLen was changed to a fixed value, the problem was gone. Why variable length malloc doesn't work properly? Anything wrong in functions above?
Any help will be appreciated.
Thank you!