Dynamic allocation malloc() or pvPortMalloc() is safe?

jeemon wrote on Tuesday, July 21, 2015:

Which is more safe to use in an application developed using FREERTOS? pvPortMalloc() or malloc()?
I used dynamic allocation (malloc()) to allocate memory and the code execution gone to hard fault handler. Instead, when I used pvPortMalloc() of heap2, it worked well even without increasing its task’s stack memory. Also malloc() is well defined in my code(I have used it before).

Thanks in Advance
Jeemon Joy

rtel wrote on Tuesday, July 21, 2015:

The following page contains relevant comments: http://www.freertos.org/a00111.html

richard_damon wrote on Wednesday, July 22, 2015:

One key thing to remember is that parts of the library (especially things like malloc/free) may not be thread safe, and these can cause issues if you don’t protect them. Any function that uses local statics or globals (like the heap), can have problems. Some libraries have hooks in them to let you make them thread safe (giving them thread local storage or a mutex to protect themselves), but I am not sure if FreeRTOS has implemented those hooks in its port layer in many cases. Many other cases you have to add this as a wrapper (like heap3.c does).