]> granicus.if.org Git - clang/commitdiff
[analyzer] MallocChecker cleanup, more tests.
authorAnna Zaks <ganna@apple.com>
Thu, 9 Feb 2012 06:25:47 +0000 (06:25 +0000)
committerAnna Zaks <ganna@apple.com>
Thu, 9 Feb 2012 06:25:47 +0000 (06:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150155 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/malloc.c

index c110e0f6f833f4e02ab5c7aa8d52e178d580135d..8f4e805e9575f145dee4b78855b2d1147a895cd7 100644 (file)
@@ -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
index f19510b639a5893e21ff52255c86804a85e503b3..190a2548d77c54bbdcc58aaf012bf7a4bf8c6e98 100644 (file)
@@ -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);
+}