diff options
-rw-r--r-- | lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 1 | ||||
-rw-r--r-- | test/Analysis/malloc.c | 27 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index c110e0f6f8..8f4e805e95 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -352,7 +352,6 @@ ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C, const MemSpaceRegion *MS = R->getMemorySpace(); - // TODO: Pessimize this. should be behinds a flag! // Parameters, locals, statics, and globals shouldn't be freed. if (!(isa<UnknownSpaceRegion>(MS) || isa<HeapSpaceRegion>(MS))) { // FIXME: at the time this code was written, malloc() regions were diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index f19510b639..190a2548d7 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -233,10 +233,35 @@ void mallocFreeMalloc() { free(p); } -void MallocFreeUse_params() { +void mallocFreeUse_params() { int *p = malloc(12); free(p); myfoo(p); //expected-warning{{Use dynamically allocated memory after it is freed}} myfooint(*p); //expected-warning{{Use dynamically allocated memory after it is freed}} } +int *Gl; +struct GlStTy { + int *x; +}; + +struct GlStTy GlS = {0}; + +void GlobalFree() { + free(Gl); +} + +void GlobalMalloc() { + Gl = malloc(12); +} + +void GlobalStructMalloc() { + int *a = malloc(12); + GlS.x = a; +} + +void GlobalStructMallocFree() { + int *a = malloc(12); + GlS.x = a; + free(GlS.x); +} |