I have the following piece of code:
string * p = new string[8];
cout<<sizeof(p)<<endl;
free(p);
which seems ok to me but failed with:
8
a.out(85837) malloc: *** error for object 0x7fb5b3403ae8: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
Another test on an integer array worked. Is there anything special with c++ string?
See Question&Answers more detail:os