I'm trying to port an application from Linux to Mac Os X (leopard), but when I execute it, I have this error message : malloc: *** error for object 0x100160 : double free
.
I've reproduced this issue with the code below :
//main.cpp
#include <stdio.h>
#include <wchar.h>
int main(int argc, char*argv[])
{
wchar_t *b=NULL;
printf("a=%ls, b=%ls \n", L"a", b);
}
Compiled with gcc:
gcc main.cpp -o test
The output of the execution:
a=a, b=(null)
test (5337) malloc: *** error for object 0x100160 : double free
*** set a breakpoint in malloc_error_break to debug
It's strange because if I use this line : printf("a=%ls, b=%ls", b, b)
, no error are printed.
Furthermore, I can't use wprintf(L"a=%ls, b=%ls", a, b)
.
On Fedora 13, this program don't print any error.
Is it a printf bug? How can I remove this error?