It seems the iOS Asan runtime has a false positive around aligned_alloc. Steps to reproduce: Create a new empty ObjC iOS project, then at the beginning insert the line:
free(aligned_alloc(16, 128));
Check the "Address Sanitizer" box in the Scheme->Run->Diagnostics, then run it on a device.
Result:
There is a workaround, however, for anyone else who runs into this--insert this snippet somewhere in your project in global scope. It seems like posix_memalign does not have the same issue.
#if defined(__has_feature) && __has_feature(address_sanitizer)
extern "C" void *aligned_alloc(size_t __alignment, size_t __size)
{
void* ret;
int res = ::posix_memalign(&ret, __alignment, __size);
if (res == 0) { return ret; }
return nullptr;
}
#endif