]> granicus.if.org Git - clang/commitdiff
NSOrCFErrorDerefChecker: Don't leak bug type. Similar to r208110/r208155. Found by...
authorNico Weber <nicolasweber@gmx.de>
Wed, 7 May 2014 21:28:03 +0000 (21:28 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 7 May 2014 21:28:03 +0000 (21:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp

index 5a505fcef84ada69c43e88e1a0b7ad495a57314c..5c4b993f5b6ca05057dcc8818d3118cd678df2b5 100644 (file)
@@ -153,6 +153,8 @@ class NSOrCFErrorDerefChecker
     : public Checker< check::Location,
                         check::Event<ImplicitNullDerefEvent> > {
   mutable IdentifierInfo *NSErrorII, *CFErrorII;
+  mutable std::unique_ptr<NSErrorDerefBug> NSBT;
+  mutable std::unique_ptr<CFErrorDerefBug> CFBT;
 public:
   bool ShouldCheckNSError, ShouldCheckCFError;
   NSOrCFErrorDerefChecker() : NSErrorII(0), CFErrorII(0),
@@ -263,10 +265,16 @@ void NSOrCFErrorDerefChecker::checkEvent(ImplicitNullDerefEvent event) const {
   os  << " may be null";
 
   BugType *bug = 0;
-  if (isNSError)
-    bug = new NSErrorDerefBug(this);
-  else
-    bug = new CFErrorDerefBug(this);
+  if (isNSError) {
+    if (!NSBT)
+      NSBT.reset(new NSErrorDerefBug(this));
+    bug = NSBT.get();
+  }
+  else {
+    if (!CFBT)
+      CFBT.reset(new CFErrorDerefBug(this));
+    bug = CFBT.get();
+  }
   BugReport *report = new BugReport(*bug, os.str(), event.SinkNode);
   BR.emitReport(report);
 }