Using newlib and common malloc is not thread safe #78124
Labels
area: C Library
C Standard Library
area: newlib
Newlib C Standard Library
bug
The issue is a bug, or the PR is fixing a bug
priority: medium
Medium impact/importance bug
Describe the bug
Using COMMON_LIBC_MALLOC and NEWLIB_LIBC is not thread safe.
Both implementations share the same heap, but each has their own locking mechanism.
This will cause memory corruptions when malloc() and newlib (i.e. printf()) are used in different threads.
To Reproduce
Steps to reproduce the behavior:
Checkout out my branch where I've modified samples/basic/threads to use printf() and malloc():
https://github.com/talih0/zephyr/tree/malloc_newlib_crash
I could reproduce the crash on two boards: xmc47_relax_kit and sam_v71_xult.
I did not get the crash when using qemu_86.
Expected behavior
No crash.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: