Dynamic memory access checking finds the following types of warnings:
AZS: allocating zero size
Memory leak
SMR: speculative uninitialized memory read
This section describes the possible causes of the warning and a code example of when the warning might occur.
Example:
#include <stdlib> int main() { int *p = malloc(); // Allocating zero size memory block }
Possible causes: Memory is allocated but not freed before exit or escaping from the function.
Example:
int foo() { int *p = (int*) malloc(sizeof(int)); if (x) { p = (int *) malloc(5*sizeof(int)); // will cause a leak of the 1st malloc } } // The 2nd malloc leaked here
Example:
int i; if (foo(&i) != 0) /* foo returns nonzero if it has initialized i */ printf("5d\n", i);
The compiler might generate the following equivalent code for the above source:
int i; int t1, t2' t1 = foo(&i); t2 = i; /* value in i is loaded. So even if t1 is 0, we have uninitialized read due to speculative load */ if (t1 != 0) printf("%d\n", t2);