Skip to main content

IAR Embedded Workbench for RL78 5.20

MEM-delete-array-op (C++ only)

In this section:
Synopsis

A memory location allocated with new is deleted with delete[]

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

A memory location is allocated with the new operator but deleted with the delete [] operator. Use the delete operator instead.

Coding standards
CWE 762

Mismatched Memory Management Routines

CWE 763

Release of Invalid Pointer or Reference

CWE 404

Improper Resource Shutdown or Release

Code examples

The following code example fails the check and will give a warning:

int main(void)
{
  int *p = new int;
  delete[] p; //should be delete, not delete[]

  return 0;
}

The following code example passes the check and will not give a warning about this issue:


int main(void)
{
  int *p = new int;
  delete p;

  return 0;
}