...
This compliant solution complies with VOID MEM31MEM34-CPP. Free dynamically allocated memory exactly onceOnly free memory allocated dynamically, however, while handling resource cleanup in catch clauses does work, it can have several disadvantages:
...
Related Guidelines
CERT C++ Secure Coding Standard | VOID MEM31-CPP. Free dynamically allocated memory exactly once MEM32-CPP. Detect and handle memory allocation errors MEM34-CPP. Only free memory allocated dynamically |
Bibliography
[ISO/IEC 14882-2014] | 15.2, "Constructors and Destructors" |
[Meyers 96] | Item 9: "Use destructors to prevent resource leaks". |
[Stroustrup 2001] | "Exception-Safe Implementation Techniques" |
[Cline 2009] | 17.2, "I'm still not convinced: a 4-line code snippet shows that return-codes aren't any worse than exceptions; |