Debugging memory corruption? (C++)
Debugging memory corruption? (C++)
- Subject: Debugging memory corruption? (C++)
- From: Jean-Denis Muys <email@hidden>
- Date: Fri, 30 Oct 2009 16:24:11 +0100
Hi,
My code is corrupting memory and I have a hard time finding the bug. Perhaps somebody can point me to some tool or idea that has escaped me so far.
- Context: my code is a plugin written in C++ for another application (4D). Yesterday everything was OK, and then I re-factored some code to migrate it to a more light weight class hierarchy, in order to have a better division of work in prevision of another set of features to implement. Now my code crashes in one of the host application callbacks.
- tools that I cannot use:
Unfortunately the host app crashes at launch time under Instruments or MallocDebug. So I can't use them. I probably can't use the XCode "Enable Guard Malloc" command either. I tried, but after waiting for about an hour for the host app to launch, I stopped. It was either crashed or so tremendously slowed down that I couldn't do anything useful.
- tools I can and have used:
• leaks works fine and I use it daily, but is not useful for this kind of issues
• I enabled all the malloc() debugging environment variables, and indeed, malloc reports interesting things, for example:
4D(4223,0xb03cb000) malloc: *** previous incorrectly set slot=0 count=4 ptr=0x49c2ed0
4D(4223,0xb03cb000) malloc: *** tiny free list incorrect (slot=0) szone_check_all() counter=54572
*** error: check: tiny free list incorrect
*** set a breakpoint in malloc_error_break to debug
or more frequently:
4D(4154,0xb02e9000) malloc: *** error for object 0x4ba1560: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Its useful, but when I break there, it too late. My buggy code has misbehaved already, possibly quite a bit ago.
One question comes to mind right away: is there a way to call the malloc heap-checking routines from my program? I could then sprinkle my code where it makes sense with heap checks.
Somewhat related is that I have set MallocCheckHeapEach to 100. This already slows the app down quite a bit. I can probably set to an even smaller value, but I don't think I can set it to 1.
Or if I change it to 1 *at run time* how can I inform malloc that I want the frequency to change? AFAICS, it only reads those environment variables at launch time.
Any suggestion welcome (also if I have missed some debugging tools).
Jean-Denis
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden