eval::Assume,
check::RegionChanges>
{
- mutable OwningPtr<BuiltinBug> BT_DoubleFree;
- mutable OwningPtr<BuiltinBug> BT_Leak;
- mutable OwningPtr<BuiltinBug> BT_UseFree;
- mutable OwningPtr<BuiltinBug> BT_UseRelinquished;
- mutable OwningPtr<BuiltinBug> BT_BadFree;
+ mutable OwningPtr<BugType> BT_DoubleFree;
+ mutable OwningPtr<BugType> BT_Leak;
+ mutable OwningPtr<BugType> BT_UseFree;
+ mutable OwningPtr<BugType> BT_BadFree;
mutable IdentifierInfo *II_malloc, *II_free, *II_realloc, *II_calloc,
*II_valloc, *II_reallocf;
if (ExplodedNode *N = C.generateSink()) {
if (!BT_DoubleFree)
BT_DoubleFree.reset(
- new BuiltinBug("Double free",
- "Try to free a memory block that has been released"));
+ new BugType("Double free", "Memory Error"));
BugReport *R = new BugReport(*BT_DoubleFree,
- BT_DoubleFree->getDescription(), N);
+ "Attempt to free released memory", N);
R->addRange(ArgExpr->getSourceRange());
R->addVisitor(new MallocBugVisitor(Sym));
C.EmitReport(R);
SourceRange range) const {
if (ExplodedNode *N = C.generateSink()) {
if (!BT_BadFree)
- BT_BadFree.reset(new BuiltinBug("Bad free"));
+ BT_BadFree.reset(new BugType("Bad free", "Memory Error"));
SmallString<100> buf;
llvm::raw_svector_ostream os(buf);
CheckerContext &C) const {
assert(N);
if (!BT_Leak) {
- BT_Leak.reset(new BuiltinBug("Memory leak",
- "Allocated memory never released. Potential memory leak."));
+ BT_Leak.reset(new BugType("Memory leak", "Memory Error"));
// Leaks should not be reported if they are post-dominated by a sink:
// (1) Sinks are higher importance bugs.
// (2) NoReturnFunctionChecker uses sink nodes to represent paths ending
BT_Leak->setSuppressOnSink(true);
}
- BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
+ BugReport *R = new BugReport(*BT_Leak,
+ "Memory is never released; potential memory leak", N);
R->addVisitor(new MallocBugVisitor(Sym));
C.EmitReport(R);
}
if (RS && RS->isReleased()) {
if (ExplodedNode *N = C.generateSink()) {
if (!BT_UseFree)
- BT_UseFree.reset(new BuiltinBug("Use of dynamically allocated memory "
- "after it is freed."));
+ BT_UseFree.reset(new BugType("Use-after-free", "Memory Error"));
- BugReport *R = new BugReport(*BT_UseFree, BT_UseFree->getDescription(),N);
+ BugReport *R = new BugReport(*BT_UseFree,
+ "Use of memory after it is freed",N);
if (S)
R->addRange(S->getSourceRange());
R->addVisitor(new MallocBugVisitor(Sym));
void f1() {
int *p = malloc(12);
- return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+ return; // expected-warning{{Memory is never released; potential memory leak}}
}
void f2() {
int *p = malloc(12);
free(p);
- free(p); // expected-warning{{Try to free a memory block that has been released}}
+ free(p); // expected-warning{{Attempt to free released memory}}
}
void f2_realloc_0() {
int *p = malloc(12);
realloc(p,0);
- realloc(p,0); // expected-warning{{Try to free a memory block that has been released}}
+ realloc(p,0); // expected-warning{{Attempt to free released memory}}
}
void f2_realloc_1() {
void n2af1() {
int *p = my_malloc2(12);
- return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+ return; // expected-warning{{Memory is never released; potential memory leak}}
}
void af1() {
int *p = my_malloc(12);
- return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+ return; // expected-warning{{Memory is never released; potential memory leak}}
}
void af1_b() {
- int *p = my_malloc(12); // expected-warning{{Allocated memory never released. Potential memory leak.}}
+ int *p = my_malloc(12); // expected-warning{{Memory is never released; potential memory leak}}
}
void af1_c() {
void af2() {
int *p = my_malloc(12);
my_free(p);
- free(p); // expected-warning{{Try to free a memory block that has been released}}
+ free(p); // expected-warning{{Attempt to free released memory}}
}
void af2b() {
int *p = my_malloc(12);
free(p);
- my_free(p); // expected-warning{{Try to free a memory block that has been released}}
+ my_free(p); // expected-warning{{Attempt to free released memory}}
}
void af2c() {
int *p = my_malloc(12);
free(p);
- my_hold(p); // expected-warning{{Try to free a memory block that has been released}}
+ my_hold(p); // expected-warning{{Attempt to free released memory}}
}
void af2d() {
int *p = my_malloc(12);
free(p);
- my_hold2(0, 0, p); // expected-warning{{Try to free a memory block that has been released}}
+ my_hold2(0, 0, p); // expected-warning{{Attempt to free released memory}}
}
// No leak if malloc returns null.
int * af4() {
int *p = my_malloc(12);
my_free(p);
- return p; // expected-warning{{Use of dynamically allocated}}
+ return p; // expected-warning{{Use of memory after it is freed}}
}
// This case is (possibly) ok, be conservative
void f7() {
char *x = (char*) malloc(4);
free(x);
- x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+ x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
}
void f7_realloc() {
char *x = (char*) malloc(4);
realloc(x,0);
- x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+ x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
}
void PR6123() {
// CHECK: <dict>
// CHECK: <key>files</key>
// CHECK: <array>
-// CHECK: <string>/Users/zaks/workspace/llvmgit/llvm/tools/clang/test/Analysis/malloc-plist.c</string>
// CHECK: </array>
// CHECK: <key>diagnostics</key>
// CHECK: <array>
// CHECK: </array>
// CHECK: </array>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
// CHECK: <key>message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
// CHECK: </dict>
// CHECK: </array>
-// CHECK: <key>description</key><string>Allocated memory never released. Potential memory leak</string>
-// CHECK: <key>category</key><string>Logic error</string>
+// CHECK: <key>description</key><string>Memory is never released; potential memory leak</string>
+// CHECK: <key>category</key><string>Memory Error</string>
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>file</key><integer>0</integer>
// CHECK: </dict>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
// CHECK: <key>message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
// CHECK: </dict>
// CHECK: </array>
-// CHECK: <key>description</key><string>Allocated memory never released. Potential memory leak</string>
-// CHECK: <key>category</key><string>Logic error</string>
+// CHECK: <key>description</key><string>Memory is never released; potential memory leak</string>
+// CHECK: <key>category</key><string>Memory Error</string>
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: </array>
// CHECK: </array>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
// CHECK: <key>message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
// CHECK: </dict>
// CHECK: </array>
-// CHECK: <key>description</key><string>Allocated memory never released. Potential memory leak</string>
-// CHECK: <key>category</key><string>Logic error</string>
+// CHECK: <key>description</key><string>Memory is never released; potential memory leak</string>
+// CHECK: <key>category</key><string>Memory Error</string>
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>location</key>
// CHECK: <dict>
void f1() {
int *p = malloc(12);
- return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+ return; // expected-warning{{Memory is never released; potential memory leak}}
}
void f2() {
int *p = malloc(12);
free(p);
- free(p); // expected-warning{{Try to free a memory block that has been released}}
+ free(p); // expected-warning{{Attempt to free released memory}}
}
void f2_realloc_0() {
int *p = malloc(12);
realloc(p,0);
- realloc(p,0); // expected-warning{{Try to free a memory block that has been released}}
+ realloc(p,0); // expected-warning{{Attempt to free released memory}}
}
void f2_realloc_1() {
char *p = (char*)malloc(size);
if (p) {
char *q = (char*)realloc(p, sizeIn);
- char x = *q; // expected-warning {{Allocated memory never released.}}
+ char x = *q; // expected-warning {{Memory is never released; potential memory leak}}
}
}
} else {
free(r);
}
- free(p); // expected-warning {{Try to free a memory block that has been released}}
+ free(p); // expected-warning {{Attempt to free released memory}}
}
void reallocSizeZero3() {
}
void reallocPtrZero1() {
- char *r = realloc(0, 12); // expected-warning {{Allocated memory never released.}}
+ char *r = realloc(0, 12); // expected-warning {{Memory is never released; potential memory leak}}
}
void reallocPtrZero2() {
char *buf = malloc(100);
buf = (char*)realloc(buf, 0x1000000);
if (!buf) {
- return;// expected-warning {{Allocated memory never released.}}
+ return;// expected-warning {{Memory is never released; potential memory leak}}
}
free(buf);
}
void reallocRadar6337483_2() {
char *buf = malloc(100);
char *buf2 = (char*)realloc(buf, 0x1000000);
- if (!buf2) { // expected-warning {{Allocated memory never released.}}
+ if (!buf2) { // expected-warning {{Memory is never released; potential memory leak}}
;
} else {
free(buf2);
char *buf = malloc(100);
char *buf2 = (char*)realloc(buf, 0x1000000);
if (!buf2) {
- return; // expected-warning {{Allocated memory never released.}}
+ return; // expected-warning {{Memory is never released; potential memory leak}}
} else {
free(buf2);
}
char * tmp;
tmp = (char*)reallocf(buf, 0x1000000);
if (!tmp) {
- free(buf); // expected-warning {{Try to free a memory block that has been released}}
+ free(buf); // expected-warning {{Attempt to free released memory}}
return;
}
buf = tmp;
}
void reallocfPtrZero1() {
- char *r = reallocf(0, 12); // expected-warning {{Allocated memory never released.}}
+ char *r = reallocf(0, 12); // expected-warning {{Memory is never released; potential memory leak}}
}
void f7() {
char *x = (char*) malloc(4);
free(x);
- x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+ x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
}
void f7_realloc() {
char *x = (char*) malloc(4);
realloc(x,0);
- x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+ x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
}
void PR6123() {
int *p = malloc(12);
myfoo(p);
free(p);
- free(p); // expected-warning{{Try to free a memory block that has been released}}
+ free(p); // expected-warning{{Attempt to free released memory}}
}
void mallocEscapeFreeUse() {
int *p = malloc(12);
myfoo(p);
free(p);
- myfoo(p); // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+ myfoo(p); // expected-warning{{Use of memory after it is freed}}
}
int *myalloc();
int *x = malloc(12);
int *y = x;
free(y);
- myfoo(x); // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+ myfoo(x); // expected-warning{{Use of memory after it is freed}}
}
void mallocEscapeMalloc() {
int *p = malloc(12);
myfoo(p);
- p = malloc(12); // expected-warning{{Allocated memory never released. Potential memory leak.}}
+ p = malloc(12); // expected-warning{{Memory is never released; potential memory leak}}
}
void mallocMalloc() {
int *p = malloc(12);
- p = malloc(12); // expected-warning{{Allocated memory never released. Potential memory leak}}
+ p = malloc(12); // expected-warning{{Memory is never released; potential memory leak}}
}
void mallocFreeMalloc() {
void mallocFreeUse_params() {
int *p = malloc(12);
free(p);
- myfoo(p); //expected-warning{{Use of dynamically allocated memory after it is freed}}
+ myfoo(p); //expected-warning{{Use of memory after it is freed}}
}
void mallocFreeUse_params2() {
int *p = malloc(12);
free(p);
- myfooint(*p); //expected-warning{{Use of dynamically allocated memory after it is freed}}
+ myfooint(*p); //expected-warning{{Use of memory after it is freed}}
}
void mallocFailedOrNot() {
int *mallocReturnFreed() {
int *p = malloc(12);
free(p);
- return p; // expected-warning {{Use of dynamically allocated}}
+ return p; // expected-warning {{Use of memory after it is freed}}
}
int useAfterFreeStruct() {
struct StructWithInt *px= malloc(sizeof(struct StructWithInt));
px->g = 5;
free(px);
- return px->g; // expected-warning {{Use of dynamically allocated}}
+ return px->g; // expected-warning {{Use of memory after it is freed}}
}
void nonSymbolAsFirstArg(int *pp, struct StructWithInt *p);
if (p == 0)
return; // no warning
else
- return; // expected-warning {{Allocated memory never released. Potential memory leak.}}
+ return; // expected-warning {{Memory is never released; potential memory leak}}
}
void mallocAssignment() {
int vallocTest() {
char *mem = valloc(12);
- return 0; // expected-warning {{Allocated memory never released. Potential memory leak.}}
+ return 0; // expected-warning {{Memory is never released; potential memory leak}}
}
void vallocEscapeFreeUse() {
int *p = valloc(12);
myfoo(p);
free(p);
- myfoo(p); // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+ myfoo(p); // expected-warning{{Use of memory after it is freed}}
}
int *Gl;
struct X *px= malloc(sizeof(struct X));
px->p = 0;
px = s2;
- return px; // expected-warning {{Allocated memory never released. Potential memory leak.}}
+ return px; // expected-warning {{Memory is never released; potential memory leak}}
}
struct X* RegInvalidationGiveUp1() {
int *p = malloc(12);
pp = &p;
pp++;
- return 0;// expected-warning {{Allocated memory never released. Potential memory leak.}}
+ return 0;// expected-warning {{Memory is never released; potential memory leak}}
}
extern void exit(int) __attribute__ ((__noreturn__));
if (p != g)
free(p);
else
- return; // expected-warning{{Allocated memory never released. Potential memory leak}}
+ return; // expected-warning{{Memory is never released; potential memory leak}}
return;
}
p[0] = n;
p++;
}
- return p;// expected-warning {{Allocated memory never released. Potential memory leak.}}
+ return p;// expected-warning {{Memory is never released; potential memory leak}}
}
// TODO: This is a false positve that should be fixed by making CString checker smarter.