Base class destructor not virtual
Class cannot behave polymorphically for deletion of derived class objects
Description
This defect occurs
when a class has virtual
functions but not a virtual
destructor.
Risk
The presence of virtual
functions indicates
that the class is intended for use as a base class. However, if the
class does not have a virtual
destructor, it cannot
behave polymorphically for deletion of derived class objects.
If a pointer to this class refers to a derived class object, and you use the pointer to delete the object, only the base class destructor is called. Additional resources allocated in the derived class are not released and can cause a resource leak.
Fix
One possible fix is to always
use a virtual
destructor in a class that contains virtual
functions.
Examples
Result Information
Group: Object oriented |
Language: C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax: DTOR_NOT_VIRTUAL |
Impact: Medium |
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)