-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AP_MultiHeap: initialize only if heap allocation succeeded #29005
AP_MultiHeap: initialize only if heap allocation succeeded #29005
Conversation
What exactly is failing? That malloc call to initialize the heap? Moving the magic init is correct (poor review on my part, whoops) and probably needs a backport. But Theoretically™ malloc returns zero-initialized memory on ArduPilot so the clear of the used size is not necessary. Have you seen that be non-zero? |
Yes. The non-zero is the reason the allocator is failing on ESP32. The first pass through the allocator it fails at
Can post a full stack trace if evidence required - but I've seen this fail on ESP32 classic and the S3. |
The failure matches my experience, and it makes sense that the heap malloc itself is not failing because then it should crash with a null pointer dereference. But that's bad, it means the wrapping is not working. Let me see if there's an obvious cause. |
I don't see anything in https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Common/c%2B%2B.cpp that would wrap malloc for ESP32 to ensure memory is initialised to zero. Where is that meant to occur for ESP32? |
It is supposed to be done here but I suspect that doesn't get passed through to the linker because that is done by ESP-IDF: ardupilot/Tools/ardupilotwaf/boards.py Line 1064 in 5f8a655
Adding We really need to convince the team to switch to a different function name, this has been repeatedly shown to not be safe. |
Signed-off-by: Rhys Mainwaring <[email protected]>
1f5cfc1
to
729333e
Compare
I have adjusted to include this fix, please test that it works properly. |
The relevant linker flag needed to be put in the CMake script.
The relevant linker flag needed to be put in the CMake script.
729333e
to
d9e5f2d
Compare
this PR should perhaps have also had the prefix AP_HAL_ESP32 now that its been determined to be a missing --wrap on malloc in the CMake linker that was exposing the issue on esp32, but its a great find, and brings the esp32 builds closer to how chibios does its pre-zero-ing so its a good-thing. |
Ensure new_heap is not null before accessing, and initialise current heap usage.
Motivation
current_heap_usage
is not initialised to zero.