C ++ heap corruption

I did not do C ++, but decided to finish the big project I was working on. I get the following error message though ...

HEAP CORRUPTION DEFINITION: after the normal block (# 1761) in 0x17DEB940. CRT The application was detected to be written to memory after heap buffer completion.

I performed all the functions that I thought could cause this, but I'm at a loss. Is there a way to use more sophisticated debugging features to find this?

+8
c ++ debugging visual-c ++ heap-memory corruption
source share
4 answers

It sounds like a classic memory corruption error. The platform will be useful information. Without looking at the code and its complexity, there are several possibilities:

  • I assume that the runtime library will allow you to add calls to the heap verification code directly from your code. I would suggest placing heap verification code calls in various places in your code so that you can figure out where things are going wrong. You will find a place where the heap is going badly, and you will know that this was normal with the previous call. Continue to narrow this window if you need to, and then look at the code where the problem occurs.

  • If the same actions damage the same place in memory, you should be able to use a debugger to set a breakpoint (or watchpoint) on the memory changes. Some of these changes may be intended, but you should be able to find out which is the culprit.

You can use a combination of the two if your code is particularly complex, or the steps required to play it are long - a narrow section of the code that is problematic and then puts a breakpoint in the damaged memory location.

David

+4
source share

On Linux, I would recommend valgrind as a tool that will definitely tell you what went wrong. You can explore some alternatives to Windows for here .

+2
source share

Try to catch it with Intruments.

It sounds a bit like a classic C error. Are you sure you are not writing outside the array c (for example, int [xyz]) after a while or for a loop? This does not cause any errors, but you get strange effects in many spaces that have nothing to do with the part where the error lives .: p

+1
source share

Try using AppVerifier with the normal version turned on. If you then attach a debugger to the process and buy a bunch with some luck, it will break at the point where the memory block is damaged (by overflowing or underloading the block). With a little effort, you can also get a column of code that highlights each block of the heap, which also helps keep track of the error.

Keeping track of these errors can be tricky, although check out the extended Windows Debugging book for more information, which has an entire chapter on the topic.

+1
source share

All Articles