Since you seem to use standard malloc/free
are you sure they’re thread-safe ?
When using newlib as C-library it’s required to provide __malloc_lock/unlock
hooks (if supported by your newlib version). See e.g. this pretty good post for further details.