General way of solving Error: Stack around the variable ‘x’ was corrupted

Is there a general way to debug this error with VS2010?

No, there isn’t. What you have done is to somehow invoke undefined behavior. The reason these behaviors are undefined is that the general case is very hard to detect/diagnose. Sometimes it is provably impossible to do so.

There are however, a somewhat smallish number of things that typically cause your problem:

  • Improper handling of memory:
    • Deleting something twice,
    • Using the wrong type of deletion (free for something allocated with new, etc.),
    • Accessing something after it’s memory has been deleted.
  • Returning a pointer or reference to a local.
  • Reading or writing past the end of an array.

Leave a Comment