Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MEM-free-no-alloc

In this section:
Synopsis

A pointer is freed without having been allocated.

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A pointer is freed without having been allocated.

Coding standards
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 example(void) {
  int *p;
  // Do stuff
  free(p);
}

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

#include <stdlib.h>

void example(void) {
  int *p = malloc(sizeof(int));
  // Do something
  free(p);
}