[PATCH] D51137: [clang-doc] Fix memory leaks

Julie Hockett via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 22 15:48:45 PDT 2018


juliehockett created this revision.
juliehockett added reviewers: leonardchan, jakehehrlich, lebedev.ri.

Adds a virtual destructor to the base Info class.


https://reviews.llvm.org/D51137

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


Index: clang-tools-extra/clang-doc/Serialize.cpp
===================================================================
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -361,7 +361,7 @@
     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 @@
   // 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 @@
     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 @@
   // 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)};
 }
 
Index: clang-tools-extra/clang-doc/Representation.h
===================================================================
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -162,6 +162,8 @@
   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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51137.162081.patch
Type: text/x-patch
Size: 2112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180822/09741565/attachment-0001.bin>


More information about the cfe-commits mailing list