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.
Search
About
You are currently browsing the Kev weblog archives for the month June, 2007.
Latest
RSS- Avoiding OpenGL frame tearing on OS X
- Installing Trac on Apache with mod_python
- New pictures
- Apollo Simulation Project: Hello CoreSimulation
- Movie Review: Quantum of Solace
- Nerd tattoos
- OpenGL on the Mac (Part 2): Building GLSL Shaders
- More pictures up
- New pictures up
- Xcode 3.1: Open Quickly and AppleScripts
Archives
Categories
- Apple (19)
- California (14)
- Cocoa (8)
- Code (26)
- Family (13)
- Food (6)
- Interface Builder (3)
- Movies (8)
- Pictures (12)
- School (34)
- Space (5)
- Technology (8)
- Thoughts (2)
- Uncategorized (11)