[cfe-commits] r161294 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/MallocChecker.cpp test/Analysis/malloc.c

Anna Zaks ganna at apple.com
Fri Aug 3 19:04:27 PDT 2012


Author: zaks
Date: Fri Aug  3 21:04:27 2012
New Revision: 161294

URL: http://llvm.org/viewvc/llvm-project?rev=161294&view=rev
Log:
[analyzer] Malloc: remove assert since is not valid as of r161248

We can be in the situation where we did not track the symbol before
realloc was called on it.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
    cfe/trunk/test/Analysis/malloc.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=161294&r1=161293&r2=161294&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Fri Aug  3 21:04:27 2012
@@ -1569,11 +1569,6 @@
 
     // Is this is the first appearance of the reallocated symbol?
     if (!statePrev->get<RegionState>(FailedReallocSymbol)) {
-      // If we ever hit this assert, that means BugReporter has decided to skip
-      // node pairs or visit them out of order.
-      assert(state->get<RegionState>(FailedReallocSymbol) &&
-        "Missed the reallocation point");
-
       // We're at the reallocation point.
       Msg = "Attempt to reallocate memory";
       StackHint = new StackHintGeneratorForSymbol(Sym,

Modified: cfe/trunk/test/Analysis/malloc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=161294&r1=161293&r2=161294&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc.c (original)
+++ cfe/trunk/test/Analysis/malloc.c Fri Aug  3 21:04:27 2012
@@ -1007,3 +1007,15 @@
   }
   free(p); // expected-warning {{Attempt to free released memory}}
 }
+
+struct HasPtr {
+  int *p;
+};
+
+int* reallocButNoMalloc(struct HasPtr *a, int c, int size) {
+  int *s;
+  a->p = (int *)realloc(a->p, size);
+  if (a->p == 0)
+    return 0; // expected-warning{{Memory is never released; potential leak}}
+  return a->p;
+}





More information about the cfe-commits mailing list