...
Note that when an operator such as new is called, it results in a call to an overloadable operator of the same name, such as operator new(). These overloadable functions can be called directly but carry the same restrictions as their operator counterparts. That is, calling operator delete() and passing a pointer parameter has the same constraints as calling the delete operator on that pointer. Further note that the overloads are subject to scope resolution, so it is possible (but not permissible) to call a class-specific operator to allocate an object but a global operator to deallocate the object.
See MEM53-CPP. Explicitly initiate and terminate object lifetime construct and destruct objects when manually managing object lifetime for information on lifetime management of objects when using memory management functions other than the new and delete operators.
...
Additionally, this code violates MEM08-CPP. Use new and delete rather than raw memory allocation and deallocation. However, it does not violate MEM53-CPP. Explicitly initiate and terminate object lifetime construct and destruct objects when manually managing object lifetime because it complies with the MEM53-CPP-EX1 exception.
...
Additionally, this code violates MEM53-CPP. Explicitly initiate and terminate object lifetime construct and destruct objects when manually managing object lifetime.
Compliant Solution (new)
...
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Clang |
| clang-analyzer-cplusplus.NewDeleteLeaks-Wmismatched-new-delete | Checked by clang-tidy, but does not catch all violations of this rule | ||||||
| Parasoft C/C++test | 9.5 | MEM-06, MEM-12, MEM-28, MEM-29 | |||||||
| Parasoft Insure++ | Runtime detection |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
| SEI CERT C++ Coding Standard | MEM53-CPP. Explicitly initiate and terminate object lifetime construct and destruct objects when manually managing object lifetime |
| SEI CERT C Coding Standard | MEM31-C. Free dynamically allocated memory when no longer needed |
| MITRE CWE | CWE 590, Free of Memory Not on the Heap CWE 415, Double Free CWE 404, Improper Resource Shutdown or Release CWE 762, Mismatched Memory Management Routines |
...