Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
langcpp
struct Base {
  virtual ~Base() = default;
  virtual void f() {}
};

struct Derived final : Base {};

void f() {
   Base *b = new Derived[10];
   // ...
   delete [] b;
}

...

Code Block
bgColor#ccccff
langcpp
struct Base {
  virtual ~Base() = default;
  virtual void f() {}
};

struct Derived final : Base {};

void f() {
   Derived *b = new Derived[10];
   // ...
   delete [] b;
}

Risk Assessment

Attempting to destruct a polymorphic object that does not have a virtual destructor declared results in undefined destroy an array of polymorphic objects through the incorrect static type is undefined behavior. In practice, potential consequences include abnormal program termination and execution and memory leaks.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

EXP51-CPP

Low

ProbableUnlikely

LowMedium

P6P2

L2L3

Automated Detection

Tool

Version

Checker

Description

Clang

Include Page
Clang_V
Clang_V
-analyzer-checker=cplusplusChecked with clang -cc1 or (preferably) scan-build
Parasoft C/C++test9.5PB-10 
Parasoft Insure++  Runtime detection

...