fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int* ptr = new int;
  6.  
  7. cout << "before: " << ptr << ":" << *ptr << endl; //這行拿掉就會crash
  8. delete ptr;
  9. *ptr = 123;
  10. cout << "read after free: " << ptr << ":" << *ptr << endl;
  11. *ptr = 456; // write after free
  12. cout << "read after free: "<< ptr << ":" << *ptr << endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
before: 0x5611cca61c20:0
read after free: 0x5611cca61c20:123
read after free: 0x5611cca61c20:456