MEM-free-no-alloc-struct
In this section:
Synopsis
A struct field is deallocated without first having been allocated.
Enabled by default
No
Severity/Certainty
Medium/Medium

Full description
A struct field is deallocated without first having been allocated. This might cause a runtime error.
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>
struct test {
int *a;
};
void example(void) {
struct test t;
free(t.a);
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
struct test {
int *a;
};
void example(void) {
struct test t;
t.a = malloc(sizeof(int));
free(t.a);
}