From b8ff56c7267497e3424b992306a57c15f87b7f9b Mon Sep 17 00:00:00 2001 From: Julie Hockett Date: Fri, 24 Aug 2018 16:43:46 +0000 Subject: [PATCH] [clang-doc] Fix memory leaks Adds a virtual destructor to the base Info class. Differential Revision: https://reviews.llvm.org/D51137 llvm-svn: 340620 --- clang-tools-extra/clang-doc/Representation.h | 2 ++ clang-tools-extra/clang-doc/Serialize.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index 9e88bd9..7a127c0 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -162,6 +162,8 @@ struct Info { Info(const Info &Other) = delete; Info(Info &&Other) = default; + virtual ~Info() = default; + SymbolID USR = SymbolID(); // Unique identifier for the decl described by this Info. const InfoType IT = InfoType::IT_default; // InfoType of this particular Info. diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 873a9bd..4508221 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -361,7 +361,7 @@ std::unique_ptr emitInfo(const FunctionDecl *D, const FullComment *FC, I->USR = Func.Namespace[0].USR; else I->USR = SymbolID(); - I->ChildFunctions.push_back(std::move(Func)); + I->ChildFunctions.emplace_back(std::move(Func)); return std::unique_ptr{std::move(I)}; } @@ -382,7 +382,7 @@ std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC, // Wrap in enclosing scope auto I = llvm::make_unique(); I->USR = ParentUSR; - I->ChildFunctions.push_back(std::move(Func)); + I->ChildFunctions.emplace_back(std::move(Func)); return std::unique_ptr{std::move(I)}; } @@ -402,13 +402,13 @@ std::unique_ptr emitInfo(const EnumDecl *D, const FullComment *FC, case InfoType::IT_namespace: { auto I = llvm::make_unique(); I->USR = Enum.Namespace[0].USR; - I->ChildEnums.push_back(std::move(Enum)); + I->ChildEnums.emplace_back(std::move(Enum)); return std::unique_ptr{std::move(I)}; } case InfoType::IT_record: { auto I = llvm::make_unique(); I->USR = Enum.Namespace[0].USR; - I->ChildEnums.push_back(std::move(Enum)); + I->ChildEnums.emplace_back(std::move(Enum)); return std::unique_ptr{std::move(I)}; } default: @@ -419,7 +419,7 @@ std::unique_ptr emitInfo(const EnumDecl *D, const FullComment *FC, // Put in global namespace auto I = llvm::make_unique(); I->USR = SymbolID(); - I->ChildEnums.push_back(std::move(Enum)); + I->ChildEnums.emplace_back(std::move(Enum)); return std::unique_ptr{std::move(I)}; } -- 2.7.4