We are using RZN2L (R9A07G084M04GBG) custom tailored proprietary embedded board where we run networking applicaiton. We compile our code using ARM GNU TOOL chain 10 2021.10. We are facing one issue while using malloc API to allocate memory from heap.
We have FTP Server in our Firmware and one can FTP files into our File System. The way the code works that we open FTP data socket connection and transfer 1024 bytes of file data at a time. Our firmware accepts the data and initially stores in memory. Once the file transfer is complete the file data in memory is written to flash in Firmware. Note that as file data transfer progresses and more memory is required in Firmware it calls malloc + memset API to allocate / initialize new memory. After allocation of memory of bigger size memory, the old data is copied into new memory along with new file data as arrived. We observed an issue during file transfer at one point we feel that that memory becomes corrupted – malloced buffer overflows and corrupts the neighboring memory.
We have below functions to malloc API lock / unlock call:__malloc_lock() / __malloc_unlock() for locking / un-locking purpose.
We feel two possibilities when we face issues (crash) in our application which has many threads running and one of the thread makes request for memory using malloc API:
1) Malloc buffer overflowed
2)Malloc is not thread safe where a lot of threads are executing in an application
Please let me know if this is a know issue and how to fix the same