[clang-tools-extra] r340620 - [clang-doc] Fix memory leaks

Julie Hockett via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 24 09:43:46 PDT 2018


Author: juliehockett
Date: Fri Aug 24 09:43:46 2018
New Revision: 340620

URL: http://llvm.org/viewvc/llvm-project?rev=340620&view=rev
Log:
[clang-doc] Fix memory leaks

Adds a virtual destructor to the base Info class.

Differential Revision: https://reviews.llvm.org/D51137

Modified:
    clang-tools-extra/trunk/clang-doc/Representation.h
    clang-tools-extra/trunk/clang-doc/Serialize.cpp

Modified: clang-tools-extra/trunk/clang-doc/Representation.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=340620&r1=340619&r2=340620&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-doc/Representation.h (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.h Fri Aug 24 09:43:46 2018
@@ -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.

Modified: clang-tools-extra/trunk/clang-doc/Serialize.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Serialize.cpp?rev=340620&r1=340619&r2=340620&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp Fri Aug 24 09:43:46 2018
@@ -361,7 +361,7 @@ std::unique_ptr<Info> emitInfo(const Fun
     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<Info>{std::move(I)};
 }
 
@@ -382,7 +382,7 @@ std::unique_ptr<Info> emitInfo(const CXX
   // Wrap in enclosing scope
   auto I = llvm::make_unique<RecordInfo>();
   I->USR = ParentUSR;
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr<Info>{std::move(I)};
 }
 
@@ -402,13 +402,13 @@ std::unique_ptr<Info> emitInfo(const Enu
     case InfoType::IT_namespace: {
       auto I = llvm::make_unique<NamespaceInfo>();
       I->USR = Enum.Namespace[0].USR;
-      I->ChildEnums.push_back(std::move(Enum));
+      I->ChildEnums.emplace_back(std::move(Enum));
       return std::unique_ptr<Info>{std::move(I)};
     }
     case InfoType::IT_record: {
       auto I = llvm::make_unique<RecordInfo>();
       I->USR = Enum.Namespace[0].USR;
-      I->ChildEnums.push_back(std::move(Enum));
+      I->ChildEnums.emplace_back(std::move(Enum));
       return std::unique_ptr<Info>{std::move(I)};
     }
     default:
@@ -419,7 +419,7 @@ std::unique_ptr<Info> emitInfo(const Enu
   // Put in global namespace
   auto I = llvm::make_unique<NamespaceInfo>();
   I->USR = SymbolID();
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr<Info>{std::move(I)};
 }
 




More information about the cfe-commits mailing list