...
| Code Block | ||||
|---|---|---|---|---|
| ||||
struct Base {
virtual ~Base() = default;
virtual void f() {}
};
struct Derived final : Base {};
void f() {
Base *b = new Derived[10];
// ...
delete [] b;
} |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
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 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| -analyzer-checker=cplusplus | Checked with clang -cc1 or (preferably) scan-build | |||||||
| Parasoft C/C++test | 9.5 | PB-10 | |||||||
| Parasoft Insure++ | Runtime detection |
...