Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MEM-free-op

In this section:
Synopsis

Memory allocated with malloc deallocated using delete.

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

Memory allocated with malloc() or calloc() is deallocated using one of the delete operators instead of free(). This might cause a memory leak, or affect other heap memory due to corruption of stdlib's memory bookkeeping.

Coding standards
CWE 404

Improper Resource Shutdown or Release

CWE 762

Mismatched Memory Management Routines

CWE 590

Free of Memory not on the Heap

Code examples

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

#include <stdlib.h>
void f() 
{
  void *p = malloc(200);
  delete p;
}

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

#include <stdlib.h>
void f() {
  void *p = malloc(200);
  free(p);
}