This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS570LS0432: TI C library malloc() corrupts memory when heap size is 0

Expert 1226 points
Part Number: TMS570LS0432

Tool/software: TI C/C++ Compiler

There is a memory corruption issue in the memory.c code of TI's C library distributed with the ARM Optimizing C/C++ Compiler.


I see it when I specify a heap size of 0 using the --heap_size=0 argument to the linker.

Under the hood, in this situation the TI linker is allocating an 8-byte .sysmem section.

The C library library code in memory.c stores data into this section, but it implicitly requires more than 8 bytes.

The memory.c code has a pointer called sys_free which starts out pointing to the start of .sysmem.  Inside the minit() function, the code re-assigns the sys_free pointer, adding 4 bytes to it.

Afterwards, it writes 8 bytes of data to the memory pointed at by sys_free, which overruns the .sysmem section, corrupting whatever memory was stored just next to it.

--thx