I’ve got a function that returns a pointer that is malloc’d within that function, and then free that memory outside that function from within the calling function like so:
It would appear that malloc is working but it is never freeing. Eventually, after enough iterations my MallocFailed hook kicks in. I am using heap_4.c
This execution is happening within the same task. Please help!
~~~~
void doSomething(){
char *str = NULL; //Local string buffer
str = mallocInside(4);
if (str != NULL)
{
// Do lots of stuff, then:
vPortFree(str);
}
}
char* mallocInside(int x)
{
char* ret = (char*) pvPortMalloc(sizeof(char) * 255);
if(ret != NULL){
Initialize response buffer to 0/null
memset(ret,0,sizeof(ret));
// Then fill this with good stuff :-)
}
return ret;
}
~~~~