diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.cc b/intern/guardedalloc/intern/mallocn_guarded_impl.cc index 50185d54423..6cb93544772 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.cc +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.cc @@ -511,12 +511,18 @@ void *MEM_guarded_malloc_arrayN(size_t len, size_t size, const char *str) void *MEM_guarded_mallocN_aligned(size_t len, size_t alignment, const char *str) { - /* We only support alignment to a power of two. */ + /* Huge alignment values doesn't make sense and they wouldn't fit into 'short' used in the + * MemHead. */ + assert(alignment < 1024); + + /* We only support alignments that are a power of two. */ assert(IS_POW2(alignment)); - /* Use a minimal alignment of 8. Otherwise MEM_guarded_freeN thinks it is an illegal pointer. */ - if (alignment < 8) { - alignment = 8; + /* Some OS specific aligned allocators require a certain minimal alignment. */ + /* And #MEM_guarded_freeN also checks that it is freeing a pointer aligned with `sizeof(void *)`. + */ + if (alignment < ALIGNED_MALLOC_MINIMUM_ALIGNMENT) { + alignment = ALIGNED_MALLOC_MINIMUM_ALIGNMENT; } /* It's possible that MemHead's size is not properly aligned, @@ -527,11 +533,6 @@ void *MEM_guarded_mallocN_aligned(size_t len, size_t alignment, const char *str) */ size_t extra_padding = MEMHEAD_ALIGN_PADDING(alignment); - /* Huge alignment values doesn't make sense and they - * wouldn't fit into 'short' used in the MemHead. - */ - assert(alignment < 1024); - #ifdef WITH_MEM_VALGRIND const size_t len_unaligned = len; #endif