MISRAC2012-Rule-22.2_c
In this section:
Synopsis
(Mandatory) A block of memory shall only be freed if it was allocated by means of a Standard Library function
Enabled by default
Yes
Severity/Certainty
High/High

Full description
A stack address might be freed. This check is identical to MEM-free-variable, CERT-MEM34-C_a.
Coding standards
- CERT MEM34-C
Only free memory allocated dynamically
- CWE 590
Free of Memory not on the Heap
- MISRA C:2012 Rule-22.2
(Mandatory) A block of memory shall only be freed if it was allocated by means of a Standard Library function
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
void example(void){
int x=0;
free(&x);
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int *p;
p = (int *)malloc(sizeof( int));
free(p);
}