Nerd Post: EXC_BAD_ACCESS

So I spent a few days trying to find a memory corruption bug, known as the infamous EXC_BAD_ACCESS. Basically that means that you are over-freeing zones of memory. In your GBD console, you will get some message like: *** malloc[705]: error for object 0×9c5b00: Incorrect checksum for freed object - object was probably modified after being freed; break at szone_error. Hmm. That really doesn’t tell us anything.The problem with malloc errors is that enabling zombies really doesn’t do anything, same with setting symbolic breakpoints in szone_error and malloc_error_break. So what’s the solution to finding this?Guard Malloc. Guard Malloc is a hard-to-find memory bug tracking utility that is part of libgmalloc.dylib. When you run with it enabled, for every malloc(), NSZoneMalloc(), or other associated memory allocators, Guard Malloc allocates its own virtual memory page, with the end of the allocated buffer at the end of the page. Therefore whenever you access outside of the buffer, it immediately causes a bus error. In addition, when memory is freed, libgmalloc deallocates its virtual memory buffer, so read and writes to the buffer also cause immediate bus errors. When running from Xcode with Guard Malloc, the Debugger will jump to the source where the bus error occurred making these bugs really easy to find.One issue with Guard Malloc is that because of all the paging, it takes a long time to do any operation. So be prepared to wait.Overall though, Guard Malloc is great and extremely helpful.

5 Responses to “Nerd Post: EXC_BAD_ACCESS”


  1. 1 Peter Morse

    I thought macs couldn’t get sick. I mean, I didn’t understand any of that, but am I reading you right that macs can get little buggies?

    What’s the deal man, is nothing sacred?!

    -Peter

  2. 2 Kev

    Peter. Only Jesus is perfect.

  3. 3 Dani Johns

    KEVIN!
    hey I’m working at Mr. Schmidt’s office next to your Dad for the summer and he told me about your blog… I thought I should say hi and I hope your doing well! we miss you in Wheaton!!

    Dani

  4. 4 Peter Morse

    So very, very true. I guess it’s just that the way mac-addicts talk about it, it sounds like Jesus would use a mac because they are near-perfect. Oh well, I guess he uses windows after all…

  5. 5 Melissa

    Kevin, I didn’t understand one single word of that last post, but I just felt like dropping in to say hello!
    I hope California is treating you wonderfully…
    I have been very bad at responding to that email you sent me forever ago, but I will get on it soon, I PROMISE you that.

Leave a Reply

You must login to post a comment.