[clang-tools-extra] r213845 - [clang-tidy] Fix a heap use-after-free bug detected by asan.

Benjamin Kramer benny.kra at googlemail.com
Thu Jul 24 01:34:42 PDT 2014


Author: d0k
Date: Thu Jul 24 03:34:42 2014
New Revision: 213845

URL: http://llvm.org/viewvc/llvm-project?rev=213845&view=rev
Log:
[clang-tidy] Fix a heap use-after-free bug detected by asan.

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/UnusedRAII.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedRAII.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedRAII.cpp?rev=213845&r1=213844&r2=213845&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedRAII.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedRAII.cpp Thu Jul 24 03:34:42 2014
@@ -17,7 +17,7 @@ namespace clang {
 namespace ast_matchers {
 AST_MATCHER(CXXRecordDecl, hasUserDeclaredDestructor) {
   // TODO: If the dtor is there but empty we don't want to warn either.
-  return Node.hasUserDeclaredDestructor();
+  return Node.hasDefinition() && Node.hasUserDeclaredDestructor();
 }
 } // namespace ast_matchers
 
@@ -73,9 +73,9 @@ void UnusedRAIICheck::check(const MatchF
   // Otherwise just suggest adding a name. To find the place to insert the name
   // find the first TypeLoc in the children of E, which always points to the
   // written type.
-  const auto *TL =
-      selectFirst<TypeLoc>("t", match(expr(hasDescendant(typeLoc().bind("t"))),
-                                      *E, *Result.Context));
+  auto Matches =
+      match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
+  const auto *TL = selectFirst<TypeLoc>("t", Matches);
   D << FixItHint::CreateInsertion(
       Lexer::getLocForEndOfToken(TL->getLocEnd(), 0, *Result.SourceManager,
                                  Result.Context->getLangOpts()),





More information about the cfe-commits mailing list