Hi bkramer,

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

This patch makes it owned by the Check object.

http://reviews.llvm.org/D5402

Files:
  clang-tidy/google/TodoCommentCheck.cpp
  clang-tidy/google/TodoCommentCheck.h
Index: clang-tidy/google/TodoCommentCheck.cpp
===================================================================
--- clang-tidy/google/TodoCommentCheck.cpp
+++ clang-tidy/google/TodoCommentCheck.cpp
@@ -15,8 +15,7 @@
 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,14 @@
   TodoCommentCheck &Check;
   llvm::Regex TodoMatch;
 };
-} // namespace
+
+TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
+    : ClangTidyCheck(Name, Context), Handler(new TodoCommentHandler(*this)) {}
+
+TodoCommentCheck::~TodoCommentCheck() {}
 
 void TodoCommentCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  Compiler.getPreprocessor().addCommentHandler(new TodoCommentHandler(*this));
+  Compiler.getPreprocessor().addCommentHandler(Handler.get());
 }
 
 } // namespace readability
Index: clang-tidy/google/TodoCommentCheck.h
===================================================================
--- clang-tidy/google/TodoCommentCheck.h
+++ clang-tidy/google/TodoCommentCheck.h
@@ -21,9 +21,13 @@
 /// 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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to