...
DCL54-CPP-EX1: A placement deallocation function may be elided for a corresponding placement allocation function, but only if the object placement allocation and object construction are guaranteed to be noexcept(true). Because placement deallocation functions are automatically invoked when the object initialization terminates by throwing an exception, it is safe to elide the placement deallocation function when exceptions cannot be thrown. For instance, some vendors implement compiler flags disabling exception support (such as -fno-cxx-exceptions in Clang and /EHs-c- in Microsoft Visual Studio), which has implementation-defined behavior when an exception is thrown but generally results in program termination similar to calling abort().
DCL54-CPP-EX2: If one user-defined allocation or deallocation function in a pair would have the exact same behavior as the default one that it's replacing, then it does not need to be written. Instead there should be a comment saying that the behavior is the same as the default. For example, if a destroying operator delete implementation does a size calculation, calls the destructor, and then calls the global operator delete, no operator new implementation is required.
Risk Assessment
Mismatched usage of new and delete could lead to a denial-of-service attack.
Rule | Severity | Likelihood |
|---|
Detectable | Repairable | Priority | Level |
|---|---|---|---|
DCL54-CPP | Low | Probable | Yes |
No |
P4 |
L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| new-delete-pairwise | Partially checked | ||||||
| Axivion Bauhaus Suite |
| CertC++-DCL54 | |||||||
| Clang |
| misc-new-delete-overloads | Checked with clang-tidy. | ||||||
| Helix QAC |
| C++2160 | |||||||
| Klocwork |
| CERT.DCL.SAME_SCOPE_ALLOC_DEALLOC | |||||||
| Parasoft C/C++test |
| CERT_CPP-DCL54-a | Always provide new and delete together | |||||||
| Polyspace Bug Finder |
| CERT C++: DCL54-CPP | Checks for mismatch between overloaded operator new and operator delete (rule fully covered) | ||||||
| RuleChecker |
| new-delete-pairwise | Partially checked |
| SonarQube C/C++ Plugin |
| S1265 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
Bibliography
| [ISO/IEC 14882-2014] | Subclause 3.7.4, "Dynamic Storage Duration" |
|
...