[analyzer] MallocChecker: add a list of false positives based on running
the checker over postgres and sqlite. llvm-svn: 150216
This commit is contained in:
parent
3188686c55
commit
e963fd51a8
|
@ -285,3 +285,85 @@ void GlobalStructMallocFree() {
|
|||
GlS.x = a;
|
||||
free(GlS.x);
|
||||
}
|
||||
|
||||
|
||||
// Below are the known false positives.
|
||||
|
||||
// TODO: There should be no warning here.
|
||||
extern void exit(int) __attribute__ ((__noreturn__));
|
||||
void mallocExit(int *g) {
|
||||
struct xx *p = malloc(12);
|
||||
|
||||
if (g != 0) {
|
||||
exit(1); // expected-warning{{Allocated memory never released. Potential memory leak}}
|
||||
}
|
||||
free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// TODO: There should be no warning here.
|
||||
extern void __assert_fail (__const char *__assertion, __const char *__file,
|
||||
unsigned int __line, __const char *__function)
|
||||
__attribute__ ((__noreturn__));
|
||||
#define assert(expr) \
|
||||
((expr) ? (void)(0) : __assert_fail (#expr, __FILE__, __LINE__, __func__))
|
||||
void mallocAssert(int *g) {
|
||||
struct xx *p = malloc(12);
|
||||
|
||||
assert(g != 0); // expected-warning{{Allocated memory never released. Potential memory leak}}
|
||||
free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: There should be no warning here.
|
||||
unsigned takePtrToPtr(int **p);
|
||||
void PassTheAddrOfAllocatedData(int *g, int f) {
|
||||
int *p = malloc(12);
|
||||
// This call is causing the problem.
|
||||
if (takePtrToPtr(&p))
|
||||
f++; // expected-warning{{Allocated memory never released. Potential memory leak}}
|
||||
free(p); // expected-warning{{Allocated memory never released. Potential memory leak}}
|
||||
}
|
||||
|
||||
// TODO: There should be no warning here.
|
||||
void reallocFails(int *g, int f) {
|
||||
char *p = malloc(12);
|
||||
char *r = realloc(p, 12+1);
|
||||
if (!r) {
|
||||
free(p); // expected-warning {{Try to free a memory block that has been released}}
|
||||
} else {
|
||||
free(r);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: There should be no warning here. This one might be difficult to get rid of.
|
||||
void dependsOnValueOfPtr(int *g, unsigned f) {
|
||||
int *p;
|
||||
|
||||
if (f) {
|
||||
p = g;
|
||||
} else {
|
||||
p = malloc(12);
|
||||
}
|
||||
|
||||
if (p != g)
|
||||
free(p);
|
||||
else
|
||||
return; // expected-warning{{Allocated memory never released. Potential memory leak}}
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Should this be a warning?
|
||||
// Here we are returning a pointer one past the allocated value. An idiom which
|
||||
// can be used for implementing special malloc. The correct uses of this might
|
||||
// be rare enough so that we could keep this as a warning.
|
||||
static void *specialMalloc(int n){
|
||||
int *p;
|
||||
p = malloc( n+8 );
|
||||
if( p ){
|
||||
p[0] = n;
|
||||
p++;
|
||||
}
|
||||
return p;// expected-warning {{Allocated memory never released. Potential memory leak.}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue