From 9d8c8eba567740c001c0870c7db0bb24b1517939 Mon Sep 17 00:00:00 2001 From: Chris Kennelly CA Date: Sat, 29 Aug 2026 14:05:03 -0700 Subject: [PATCH] Use posix_memalign when aligned_alloc is unavailable for aligned_alloc_at_least. PiperOrigin-RevId: 973196761 --- tcmalloc/alloc_at_least.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tcmalloc/alloc_at_least.cc b/tcmalloc/alloc_at_least.cc index 6a2cb6173..ef0cec063 100644 --- a/tcmalloc/alloc_at_least.cc +++ b/tcmalloc/alloc_at_least.cc @@ -30,7 +30,18 @@ extern "C" ABSL_ATTRIBUTE_WEAK alloc_result_t alloc_at_least(size_t min_size) extern "C" ABSL_ATTRIBUTE_WEAK alloc_result_t aligned_alloc_at_least( size_t alignment, size_t min_size) ALLOC_AT_LEAST_NOEXCEPT { alloc_result_t result; +#if !defined(_ISOC11_SOURCE) + void* ptr = nullptr; + if (posix_memalign(&ptr, alignment, min_size) == 0) { + result.ptr = ptr; + result.size = min_size; + } else { + result.ptr = nullptr; + result.size = 0; + } +#else result.ptr = std::aligned_alloc(alignment, min_size); result.size = result.ptr != nullptr ? min_size : 0; +#endif return result; }