Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
Include Page
Clang_V
Clang_V
clang-analyzer-cplusplus.NewDeleteLeaks
-Wmismatched-new-delete
clang-analyzer-unix.MismatchedDeallocator 
Checked by clang-tidy, but does not catch all violations of this rule
Parasoft C/C++test9.5MEM-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.

...

...