Tutorial :What could cause DAMAGE: after normal block error?


I keep getting this error after my application is running for 2 days.

I've been told it's been some kind of buffer overflow, but is it the only option?

The app is written in C++ using Visual C++ 6.0.


In debug, when you get dynamic buffer by new, a special code gets inserted before and after the buffer to guard the buffer.


<Guard>=====buffer allocated on heap of required size=======<Guard>  

If you overrun the buffer, the guard inserted gets corrupted and when you try to delete the buffer, then debugger would assert after detecting buffer overrun.

Its bit difficult to find the buffer overrun in large code base. I would suggest couple of ways which can help you to detect this scenario:

  • Using tools like Rational Purify:
    Its good tool to detect memory corruption.
  • Debugging by Windbg with GFlags enabled: Refer my answer to similar question here


The simplest way to reproduce this is something like this:

//Allocate space for holding 10 ints  int *p = new int[10];    //Overwrite the memory.. doesn't crash here  p[10] = 8;    //Try to delete..crashes..  delete[] p;  

Check whether you are writing to the memory location beyond its allocated space.


With the correct options, Visual C++ throws a guard value at the end of each buffer. When you free the buffer, it checks that this is still valid. If not, it raises the error that you're seeing.

The most common cause of this error is a buffer overrun. However, it can (theoretically) be caused by a random pointer write (after all, it could write to the guard value).

Odds are, though, it's an overrun.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »