iOS: AddressSanitizer false positive: aligned_alloc -> free

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

It sounds like your goal is to file a bug. If so, please do that using Feedback Assistant. See Bug Reporting: How and Why? for more.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for the prompt reply. It's been filed as issue FB12010309

iOS: AddressSanitizer false positive: aligned_alloc -> free
 
 
Q