Listing 6: Demonstrates heap corruption

void MemoryCorruption(void)
{
  AppWatchMan  myAppWatchMan;
  myAppWatchMan.DoRounds("Before Test",
                            AWM::BEGIN_CONF_CHECK);

  char* pBufferA = new char [sizeof("Hello World")];
  cout << "** Write 1 char past end of pBufferA!" << endl;
  strcpy(pBufferA, "Hello World!");  // oops!
  delete [] pBufferA;

  char* pBufferB = new char [sizeof("Goodbye")];
  cout << "** Write 1 char past end of pBufferB!" << endl;
  strcpy(pBufferB, "Goodbye!");  // oops!
  // delete [] pBufferB;  // intentional

  myAppWatchMan.DoRounds("After Test", AWM::END_CONF_CHECK);

}
— End of Listing —