Fix memalign usage

- Alignment should be above sizeof(void*)
- Don't call with very large sizes
This commit is contained in:
Matthew Parkinson
2021-12-14 11:48:45 +00:00
committed by Matthew Parkinson
parent 37d2ac42af
commit f398545154

View File

@@ -52,6 +52,16 @@ namespace snmalloc::external_alloc
{
inline void* aligned_alloc(size_t alignment, size_t size)
{
// TSAN complains if allocation is large than this.
if constexpr (bits::BITS == 64)
{
if (size >= 0x10000000000)
return nullptr;
}
if (alignment < sizeof(void*))
alignment = sizeof(void*);
void* result;
if (posix_memalign(&result, alignment, size) != 0)
{