I have a very simple C++ code here:
char *s = new char[100];
strcpy(s, \"HELLO\");
delete [] s;
int n = strlen(s);
If I run this code from
I also want to know if it's possible to stably reproduce the Access Violation crash caused from accessing deleted area?
Instead of plain delete
you could consider using an inline function that also sets the value of the deleted pointer to 0/NULL. This will typically crash if you reference it. However, it won't complain if you delete it a second time.
Is this kind of crash rare in real-life?
No, this kind of crash is probably behind the majority of the crashes you and I see in software.