]> granicus.if.org Git - clang/commitdiff
Fix possible memory leak by using an OwningPtr.
authorTed Kremenek <kremenek@apple.com>
Tue, 19 Jan 2010 01:29:05 +0000 (01:29 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 19 Jan 2010 01:29:05 +0000 (01:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93834 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Driver.cpp

index ab4bd49dd65308ebe4781c2ad7068811de2de57d..b073c0ae1ef9823ef7596e1461c0fd2a9a04df4f 100644 (file)
@@ -26,6 +26,7 @@
 #include "clang/Basic/Version.h"
 
 #include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
@@ -675,7 +676,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
     }
 
     // Build the pipeline for this file.
-    Action *Current = new InputAction(*InputArg, InputType);
+    llvm::OwningPtr<Action> Current(new InputAction(*InputArg, InputType));
     for (unsigned i = 0; i != NumSteps; ++i) {
       phases::ID Phase = types::getCompilationPhase(InputType, i);
 
@@ -686,8 +687,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
       // Queue linker inputs.
       if (Phase == phases::Link) {
         assert(i + 1 == NumSteps && "linking must be final compilation step.");
-        LinkerInputs.push_back(Current);
-        Current = 0;
+        LinkerInputs.push_back(Current.take());
         break;
       }
 
@@ -698,14 +698,14 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
         continue;
 
       // Otherwise construct the appropriate action.
-      Current = ConstructPhaseAction(Args, Phase, Current);
+      Current.reset(ConstructPhaseAction(Args, Phase, Current.take()));
       if (Current->getType() == types::TY_Nothing)
         break;
     }
 
     // If we ended with something, add to the output list.
     if (Current)
-      Actions.push_back(Current);
+      Actions.push_back(Current.take());
   }
 
   // Add a link action if necessary.