Repository navigation
Fix heap allocations with small alignment on macOS/Windows - #48
Merged
Merged
Conversation
HeapArena::Alloc forwarded alignof(T) straight to aligned_alloc/_aligned_malloc. For char arrays (String / TArray<char>) that is 1, which aligned_alloc rejects on macOS (returns NULL) and _aligned_malloc mishandles on Windows (heap corruption), so the first String move during static init crashed the test runner. Fall back to the unaligned path for alignments at or below the platform default and round the size up to a multiple of the alignment otherwise.
…n/memalign/_aligned_malloc)
- MSVC / MinGW (MSVCRT >= 7): _aligned_malloc / _aligned_free - MinGW (older): __mingw_aligned_malloc / __mingw_aligned_free - Android / SunOS: memalign / free - POSIX (Linux, macOS, iOS, BSD): posix_memalign (clamped to sizeof(void*)) / free posix_memalign and memalign avoid C11 aligned_alloc's size-multiple requirement, and _aligned_malloc is the only aligned allocator MSVC provides.
…pFree HeapAlloc(size) used _aligned_malloc under P_PLATFORM_WINDOWS (which also covers older MinGW), while HeapFree dispatches older MinGW to __mingw_aligned_free - a mismatch. Route the unaligned path through the same MSVC / MinGW / POSIX branches so every allocation pairs with its free.
CMake always passes -DP_PLATFORM_LINUX=1 on Linux (and Android), so the #ifndef P_PLATFORM_LINUX block was skipped entirely and P_PLATFORM_ANDROID was never defined. That made the Android memalign branch (and its <malloc.h> include) dead code. Detect Android in its own block.
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.
HeapArena::Allocforwardedalignof(T)straight toaligned_alloc/_aligned_malloc. For char arrays (String/TArray<char>) that is 1, whichaligned_allocrejects on macOS (returns NULL) and_aligned_mallocmishandles on Windows (heap corruption). This crashed the firstStringmove during static init in test runners.Fall back to the unaligned path for alignments at or below the platform default and round the size up to a multiple of the alignment otherwise.