0

I am chasing a memory heap corruption error. All I have is the memory address that has purportedly been modified after being freed. Windows basically triggers a breakpoint on exit and I see an error message in the Output Window as follows:

HEAP[myprogram.exe]: HEAP: Free Heap block df56c20 modified at df56c80 after it was freed 

My question is at the exact point when Windows triggers the breakpoint, can I trace back to the point in my code corresponding to the data associated with this address? That would at least help debug this. Appreciate any ideas on how I could go about doing this. I read http://msdn.microsoft.com/en-us/library/s3aw423e.aspx but it wasn't terribly clear how I could go about doing what I wanted. Thanks!

2 Answers 2

1

You can set a breakpoint at a memory address. Just go to the breakpoints window and add a new data breakpoint. This can help if you see the corruption happening at the same address for each run.

However with issues like this, the problem is most likely somewhere else. Common causes come from undefined behavior. Look for:

  • double deletes
  • not returning from a function
  • going out of bounds in an array
  • writing to memory you don't own
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks @Luchian: I just tried that but by that point, the code seems to be Windows libraries ntdll.dll with no call stack leading back to my application, and the problem is that this address is not fixed with each run; so I don't know its hex-representation a priori. If I knew that a priori I would've put it to begin with before even starting debugging. Any suggestions?
@squashed.bugaboo remove code until you no longer get the corruption. That should narrow it down.
Thanks @Luchian: OK.. I see, so you are basically suggesting (what I was putting off), to revert back to a working version of the code that didn't have the error. Am I stating you correctly?
@squashed.bugaboo yes, the cause is in the difference between the versions.
Thanks. OK. I will certainly do that, but to go back to my question tho' is there any utility (3rd party also) that can trace back to application data from a memory address at a Window triggered breakpoint? I've tried Visual Leak Detector. But it happily says there are no leaks on exit and right after that I get the Windows triggered error message. It seems like there should be something around to trace back from memory address in situations like this.
0

Use Application Verifier and enable PageHeap. That will break into the debugger immediately upon corruption of the memory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.