C++ Heap Corruption
I haven't done any C++ in a while, but decided to finish a big project I was working on for someone. I am getting the following error message now though...
HEAP CORRUPTION DETECTED: after Normal Block (#1761) at 0x17DEB940. CRT Detected that the application wrote to memory after end of heap buffer.
I have been stepping through all of the functions I thought might have caused it but I am at a loss. Is there any way using the more advanced debugging features to hunt this down?
It does sound like a classic memory corruption error. The platform would be helpful information. Without seeing your code and it's complexity there are a couple of possibilities:
I'll make a guess that the runtime library would allow you to add calls to the heap validation code directly from your code. I would suggest placing calls to the heap validation code in various places in your code so you can figure out where things go wrong. You'll find the place where the heap goes bad and you'll know that it was ok at the previous call. Keep narrowing down that window if you need to and then review the code where the problem occurs.
If the same steps corrupt exactly the same place in memory, you should be able to use your debugger to set a breakpoint (or watchpoint) on the memory getting changed. Some of those changes may be intended, but you should be able to figure out which one is the culprit.
You might use a combination of the two if your code is particularly complex or the steps needed to reproduce this are long - narrow down a section of code that it problematic and then place a breakpoint on the memory location that gets corrupted.
david
On Linux I would recommend valgrind as a tool that would tell you exactly what went wrong. You may look into some Windows alternatives for it here.
Try to catch it with Intruments.
Sounds a bit like a classical C error. You are sure you don't write beyond an c array ( like int[xyz]) in a while or for loop? It don't cause any errors, but you get strange effects in a lot spaces that have nothing to do with the part where the bug lives. :p
链接地址: http://www.djcxy.com/p/14446.html上一篇: 可能堆腐败,但它可能是别的东西?
下一篇: C ++堆损坏