Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Dir-4.13_g

In this section:
Synopsis

(Advisory) Functions which are designed to provide operations on a resource should be called in an appropriate sequence. 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
MISRA C:2012 Dir-4.13

(Advisory) Functions which are designed to provide operations on a resource should be called in an appropriate sequence

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);
}