[clang-tools-extra] r218068 - [clang-tidy] Don't leak the TodoCommentHandler object

Hans Wennborg hans at hanshq.net
Thu Sep 18 11:59:51 PDT 2014


Author: hans
Date: Thu Sep 18 13:59:50 2014
New Revision: 218068

URL: http://llvm.org/viewvc/llvm-project?rev=218068&view=rev
Log:
[clang-tidy] Don't leak the TodoCommentHandler object

Preprocessor:addCommentHandler() does not take ownership,
so we'd end up leaking the TodoCommentHandler.

This patch makes it owned by the Check object.

Differential Revision: http://reviews.llvm.org/D5402

Modified:
    clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp?rev=218068&r1=218067&r2=218068&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp Thu Sep 18 13:59:50 2014
@@ -15,8 +15,7 @@ namespace clang {
 namespace tidy {
 namespace readability {
 
-namespace {
-class TodoCommentHandler : public CommentHandler {
+class TodoCommentCheck::TodoCommentHandler : public CommentHandler {
 public:
   explicit TodoCommentHandler(TodoCommentCheck &Check)
       : Check(Check), TodoMatch("^// *TODO(\\(.*\\))?:?( )?(.*)$") {}
@@ -54,10 +53,15 @@ private:
   TodoCommentCheck &Check;
   llvm::Regex TodoMatch;
 };
-} // namespace
+
+TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
+    : ClangTidyCheck(Name, Context),
+      Handler(llvm::make_unique<TodoCommentHandler>(*this)) {}
+
+TodoCommentCheck::~TodoCommentCheck() {}
 
 void TodoCommentCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addCommentHandler(new TodoCommentHandler(*this));
+  Compiler.getPreprocessor().addCommentHandler(Handler.get());
 }
 
 } // namespace readability

Modified: clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h?rev=218068&r1=218067&r2=218068&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h Thu Sep 18 13:59:50 2014
@@ -21,9 +21,13 @@ namespace readability {
 /// Corresponding cpplint.py check: readability/todo
 class TodoCommentCheck : public ClangTidyCheck {
 public:
-  TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
-      : ClangTidyCheck(Name, Context) {}
+  TodoCommentCheck(StringRef Name, ClangTidyContext *Context);
+  ~TodoCommentCheck();
   void registerPPCallbacks(CompilerInstance &Compiler) override;
+
+private:
+  class TodoCommentHandler;
+  std::unique_ptr<TodoCommentHandler> Handler;
 };
 
 } // namespace readability





More information about the cfe-commits mailing list