Use posix_memalign on POSIX systems when explicitly enabled. The portable aligned_alloc below stores metadata at ptr[-1], which conflicts with ASAN's heap redzone and causes intermittent bus errors.
| 174 | // The portable aligned_alloc below stores metadata at ptr[-1], which conflicts |
| 175 | // with ASAN's heap redzone and causes intermittent bus errors. |
| 176 | inline void *aligned_alloc(size_t align, size_t size) |
| 177 | { |
| 178 | align = std::max(align, sizeof(void*)); // posix_memalign requires align >= sizeof(void*) |
| 179 | void *ptr = nullptr; |
| 180 | if (posix_memalign(&ptr, align, size) != 0) |
| 181 | throw std::bad_alloc(); |
| 182 | return ptr; |
| 183 | } |
| 184 | inline void aligned_dealloc(void *ptr) |
| 185 | { free(ptr); } |
| 186 | #else |
no test coverage detected