MacOSKeychainAPIChecker: Do not report double allocation if first allocation returned an error.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137720 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
index 0b369d7..8470dc6 100644
--- a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
@@ -230,23 +230,25 @@
     const Expr *ArgExpr = CE->getArg(FunctionsToTrack[idx].Param);
     if (SymbolRef V = getAsPointeeSymbol(ArgExpr, C))
       if (const AllocationState *AS = State->get<AllocatedData>(V)) {
-        // Remove the value from the state. The new symbol will be added for
-        // tracking when the second allocator is processed in checkPostStmt().
-        State = State->remove<AllocatedData>(V);
-        ExplodedNode *N = C.generateNode(State);
-        if (!N)
-          return;
-        initBugType();
-        llvm::SmallString<128> sbuf;
-        llvm::raw_svector_ostream os(sbuf);
-        unsigned int DIdx = FunctionsToTrack[AS->AllocatorIdx].DeallocatorIdx;
-        os << "Allocated data should be released before another call to "
-           << "the allocator: missing a call to '"
-           << FunctionsToTrack[DIdx].Name
-           << "'.";
-        RangedBugReport *Report = new RangedBugReport(*BT, os.str(), N);
-        Report->addRange(ArgExpr->getSourceRange());
-        C.EmitReport(Report);
+        if (!definitelyReturnedError(AS->RetValue, State, C.getSValBuilder())) {
+          // Remove the value from the state. The new symbol will be added for
+          // tracking when the second allocator is processed in checkPostStmt().
+          State = State->remove<AllocatedData>(V);
+          ExplodedNode *N = C.generateNode(State);
+          if (!N)
+            return;
+          initBugType();
+          llvm::SmallString<128> sbuf;
+          llvm::raw_svector_ostream os(sbuf);
+          unsigned int DIdx = FunctionsToTrack[AS->AllocatorIdx].DeallocatorIdx;
+          os << "Allocated data should be released before another call to "
+              << "the allocator: missing a call to '"
+              << FunctionsToTrack[DIdx].Name
+              << "'.";
+          RangedBugReport *Report = new RangedBugReport(*BT, os.str(), N);
+          Report->addRange(ArgExpr->getSourceRange());
+          C.EmitReport(Report);
+        }
       }
     return;
   }