#include <iostream>
using namespace std;
int main() {
int* ptr = new int;
cout << "before: " << ptr << ":" << *ptr << endl; //這行拿掉就會crash
delete ptr;
*ptr = 123;
cout << "read after free: " << ptr << ":" << *ptr << endl;
*ptr = 456; // write after free
cout << "read after free: "<< ptr << ":" << *ptr << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgaW50KiBwdHIgPSBuZXcgaW50OwogIAogIGNvdXQgPDwgImJlZm9yZTogIiA8PCBwdHIgPDwgIjoiIDw8ICpwdHIgPDwgZW5kbDsgLy/pgJnooYzmi7/mjonlsLHmnINjcmFzaAogIGRlbGV0ZSBwdHI7CiAgKnB0ciAgICAgPSAxMjM7CiAgY291dCA8PCAicmVhZCBhZnRlciBmcmVlOiAiIDw8IHB0ciA8PCAiOiIgPDwgKnB0ciA8PCBlbmRsOwogICpwdHIgPSA0NTY7IC8vIHdyaXRlIGFmdGVyIGZyZWUKICBjb3V0IDw8ICJyZWFkIGFmdGVyIGZyZWU6ICI8PCBwdHIgPDwgIjoiIDw8ICpwdHIgPDwgZW5kbDsKICByZXR1cm4gMDsKfQ==