diff options
author | Nico Weber <nicolasweber@gmx.de> | 2014-04-28 04:57:14 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2014-04-28 04:57:14 +0000 |
commit | d53fa2e0646e4f1182d4fa47f9934756ba2d8b73 (patch) | |
tree | 285d23a9cd8bd8c036310308129090296fe28648 | |
parent | 113a55fb4314b0e025ffc9e95769eb5f478062ef (diff) | |
download | clang_35a-d53fa2e0646e4f1182d4fa47f9934756ba2d8b73.tar.gz |
Follow-up to r207071: Let newFrontendActionFactory() return a unique_ptr.
This exposed a leak, fix that.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207396 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Tooling/Tooling.h | 18 | ||||
-rw-r--r-- | tools/clang-check/ClangCheck.cpp | 4 |
2 files changed, 12 insertions, 10 deletions
diff --git a/include/clang/Tooling/Tooling.h b/include/clang/Tooling/Tooling.h index ece38fc7e7..a0d6cb789c 100644 --- a/include/clang/Tooling/Tooling.h +++ b/include/clang/Tooling/Tooling.h @@ -97,7 +97,7 @@ public: /// FrontendActionFactory *Factory = /// newFrontendActionFactory<clang::SyntaxOnlyAction>(); template <typename T> -FrontendActionFactory *newFrontendActionFactory(); +std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(); /// \brief Callbacks called before and after each source file processed by a /// FrontendAction created by the FrontedActionFactory returned by \c @@ -126,10 +126,10 @@ public: /// struct ProvidesASTConsumers { /// clang::ASTConsumer *newASTConsumer(); /// } Factory; -/// FrontendActionFactory *FactoryAdapter = -/// newFrontendActionFactory(&Factory); +/// std::unique_ptr<FrontendActionFactory> FactoryAdapter( +/// newFrontendActionFactory(&Factory)); template <typename FactoryT> -inline FrontendActionFactory *newFrontendActionFactory( +inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory( FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks = NULL); /// \brief Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag. @@ -305,17 +305,18 @@ class ClangTool { }; template <typename T> -FrontendActionFactory *newFrontendActionFactory() { +std::unique_ptr<FrontendActionFactory> newFrontendActionFactory() { class SimpleFrontendActionFactory : public FrontendActionFactory { public: clang::FrontendAction *create() override { return new T; } }; - return new SimpleFrontendActionFactory; + return std::unique_ptr<FrontendActionFactory>( + new SimpleFrontendActionFactory); } template <typename FactoryT> -inline FrontendActionFactory *newFrontendActionFactory( +inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory( FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks) { class FrontendActionFactoryAdapter : public FrontendActionFactory { public: @@ -362,7 +363,8 @@ inline FrontendActionFactory *newFrontendActionFactory( SourceFileCallbacks *Callbacks; }; - return new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks); + return std::unique_ptr<FrontendActionFactory>( + new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks)); } /// \brief Returns the absolute path of \c File, by prepending it with diff --git a/tools/clang-check/ClangCheck.cpp b/tools/clang-check/ClangCheck.cpp index 4fc970c0d1..cc8d43cec2 100644 --- a/tools/clang-check/ClangCheck.cpp +++ b/tools/clang-check/ClangCheck.cpp @@ -215,7 +215,7 @@ int main(int argc, const char **argv) { Analyze ? "--analyze" : "-fsyntax-only", InsertAdjuster::BEGIN)); clang_check::ClangCheckActionFactory CheckFactory; - FrontendActionFactory *FrontendFactory; + std::unique_ptr<FrontendActionFactory> FrontendFactory; // Choose the correct factory based on the selected mode. if (Analyze) @@ -225,5 +225,5 @@ int main(int argc, const char **argv) { else FrontendFactory = newFrontendActionFactory(&CheckFactory); - return Tool.run(FrontendFactory); + return Tool.run(FrontendFactory.get()); } |