Thursday, October 15, 2015

MallocNanoZone=1 Makes for Hard Debugging

Gus Mueller:

Then it happened again, and I found a pretty reliable way to reproduce it. But again I wasn't running from Xcode and when I launched it from Xcode I couldn't reproduce it.

[…]

So what does the MallocNanoZone env variable do? It's a flag that changes the memory allocator for your app, and for the frameworks your app uses. I don't know the specifics of this allocator vs whatever the normal one is, but I do know how it hid this bug from me in Acorn. When MallocNanoZone was set, the allocator worked in such a way that when I used CFRelease with a CGImageRef, and then used CGImageGetWidth with that same (bad) reference, it would return the correct answer (CGImageCreateCopyWithColorSpace() may have been involved as well). When MallocNanoZone was off the normal allocator was used and CGImageGetWidth would return a bad answer (as it should!).

1 Comment RSS · Twitter


Accessing release memory in an undefined behavior. Both responses are perfectly right. The "as it should!" comment is just a wrong assumption.

Leave a Comment