Double Frees in Modern C++
Modern C++ solves this differently:
1. std::string s1 = "Cpp";
2. std::string s2 = s1; // Duplicate the data in s1.
- The heap data from
s1is duplicated ands2gets its own independent copy. - When
s1ands2go out of scope, they each free their own memory.
Before copy-assignment:

After copy-assignment:

