site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com On Apr 27, 2011, at 12:53 AM, Ronald S. Bultje wrote:
Hi,
I hope this is the right list for my problem. I have the following problem (let's call this my testcase for the problem I'm seeing in my application):
bash-3.2$ cat test.c #include <stdlib.h> int main(){ void *ptr = NULL; if (posix_memalign(&ptr, 16, 0)) return; if (ptr) free(ptr); if (posix_memalign(&ptr, 32, 0)) return; if (ptr) free(ptr); } bash-3.2$ gdb ./test [..] (gdb) r Starting program: /private/tmp/test Reading symbols for shared libraries +. done test(72919) malloc: *** error for object 0x1001000a0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug
Program received signal SIGABRT, Aborted. 0x00007fff88679616 in __kill () (gdb) bt #0 0x00007fff88679616 in __kill () #1 0x00007fff88719cca in abort () #2 0x00007fff886316f5 in free () #3 0x0000000100000f17 in main () at test.c:7
It seems that posix_memalign() with alignment=16 accepts size=0 fine, but with alignment=32, it does not. This works fine (as far as I can see) on other systems that I have access to (Linux on PPC/x86/Arm, Windows). System is MacOSX 10.6.7, on a recent Macbook Pro. Is this a bug, and if so, is it a known bug?
Seems to be, at least according to kernel.org, perhaps expected... http://www.kernel.org/doc/man-pages/online/pages/man3/posix_memalign.3.html "If size is 0, then posix_memalign() returns either NULL, or a unique pointer value that can later be successfully passed to free(3)." I'm not to keen on a function either returning NULL or something not NULL, but it would seem that when you align @ 32 here, you're getting a NULL return, hence the failure in FREE since nothing got malloc'ed in that case. It also looks like this has been reported to and patched in FreeBSD several years ago, but I'm novice enough with kernel code that this may be a separate yet similar problem: http://freebsd.1045724.n5.nabble.com/standards-138307-posix-memalign-has-inc... -- Mike _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com