fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A {
  5. char * data;
  6. A() {
  7. data = new char[10000];
  8. std::cout << "A()" << std::endl;
  9. }
  10.  
  11. ~A() {
  12. if(data != nullptr) {
  13. delete data;
  14. std::cout << "Deleted Data!" << std::endl;
  15. }
  16. std::cout << "~A() " << std::endl;
  17. }
  18. };
  19.  
  20. void aDo2(A && a) {
  21. cout << "Do2" << endl;
  22. }
  23.  
  24. void aDo(A && a) {
  25. cout << "Do" << endl;
  26. aDo2(A(a));
  27. }
  28.  
  29.  
  30.  
  31. int main() {
  32. {
  33. A a;
  34. {
  35. aDo(move(a));
  36. }
  37.  
  38. cout << "why" << endl;
  39. }
  40. cout << "here?" << endl;
  41. // your code goes here
  42. return 0;
  43. }
Runtime error #stdin #stdout #stderr 0s 3280KB
stdin
Standard input is empty
stdout
A()
Do
Do2
Deleted Data!
~A() 
why
stderr
*** Error in `./prog': double free or corruption (top): 0x081bf008 ***