I have some C++ code in my OS X project that allocates an array thusly:
C * p = new C[lengthHint + 2];
This is in a template class;
lengthHint is 1. This is all irrelevant. The error I get at runtime is:
malloc: *** error for object 0x60800000c4f0: Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug
malloc is failing because a previous call to
free freed something that wasn't valid. But it seems like
free would've complained about that at the time.
Obviously there are millions of
new/delete calls being executed and this same code is running without issues in other programs running on iOS and OS X. I'm not sure how to approach debugging this and am looking for suggestions.