Delete of void pointer
delete operates on a void* pointer
pointing to an object
Description
This defect occurs
when the delete operator operates on a void* pointer.
Risk
Deleting a void* pointer is undefined according
to the C++ Standard.
If the object is of type MyClass and the delete operator
operates on a void* pointer pointing to the object,
the MyClass destructor is not called.
If the destructor contains cleanup operations such as release of resources or decreasing a counter value, the operations do not take place.
Fix
Cast the void* pointer to the appropriate
type. Perform the delete operation on the result
of the cast.
For instance, if the void* pointer points
to a MyClass object, cast the pointer to MyClass*.
Examples
Result Information
| Group: Good practice |
| Language: C++ |
| Default: Off |
Command-Line Syntax: DELETE_OF_VOID_PTR |
| Impact: Low |
Version History
Introduced in R2015b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)