]> granicus.if.org Git - clang/commitdiff
[analyzer] Malloc: remove assert since is not valid as of r161248
authorAnna Zaks <ganna@apple.com>
Sat, 4 Aug 2012 02:04:27 +0000 (02:04 +0000)
committerAnna Zaks <ganna@apple.com>
Sat, 4 Aug 2012 02:04:27 +0000 (02:04 +0000)
We can be in the situation where we did not track the symbol before
realloc was called on it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161294 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0a36071cf7c35483473a95da0aa96fc85f66d636..4f19c2ee079eeb518f56bc6c85a8e27c88407955 100644 (file)
@@ -1569,11 +1569,6 @@ MallocChecker::MallocBugVisitor::VisitNode(const ExplodedNode *N,
 
     // 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,
index 964424647f6ff4b3ec240b9d4875f197aa527a72..7f5062af458336db28dc97fe2defe19846237417 100644 (file)
@@ -1007,3 +1007,15 @@ void freeButNoMalloc(int *p, int x){
   }
   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;
+}