Fix cmpctmalloc crash for large aligned allocations.#112
Merged
floitsch merged 2 commits intopatch-head-5.4.2from Mar 18, 2026
Merged
Fix cmpctmalloc crash for large aligned allocations.#112floitsch merged 2 commits intopatch-head-5.4.2from
floitsch merged 2 commits intopatch-head-5.4.2from
Conversation
The aligned alloc path didn't check size before entering the bucket allocator. On ESP32-P4, cache alignment requirements (64 bytes) put large allocations (e.g. 32KB DMA pool) into the bucket path instead of page_alloc, causing a fatal in size_to_index_helper.
erikcorry
approved these changes
Mar 15, 2026
There was a problem hiding this comment.
Just add " || size >= PAGE_SIZE / 4 * 3" here
The obvious choice of using SMALL_ALLOCATION_LIMIT has some issues because aligned allocations get rounded up a bit later and could hit the limit. This is a safe choice, but you could also copy the limit from the regular unaligned path, which is designed to avoid fragmentation.
if (size < ALMOST_FULL_PAGE ||
(PAGE_SIZE < size && size <= PAGE_AND_A_HALF)) {
erikcorry
approved these changes
Mar 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The aligned alloc path didn't check size before entering the bucket allocator. On ESP32-P4, cache alignment requirements (64 bytes) put large allocations (e.g. 32KB DMA pool) into the bucket path instead of page_alloc, causing a fatal in size_to_index_helper.