1
0
Эх сурвалжийг харах

Modernize memory management

Update internals of various classes
Marc Chevrier 5 жил өмнө
parent
commit
557cecdc3d

+ 9 - 25
Source/cmCPluginAPI.cxx

@@ -488,24 +488,8 @@ struct cmCPluginAPISourceFile
 
 // Keep a map from real cmSourceFile instances stored in a makefile to
 // the CPluginAPI proxy source file.
-class cmCPluginAPISourceFileMap
-  : public std::map<cmSourceFile*, cmCPluginAPISourceFile*>
-{
-public:
-  using derived = std::map<cmSourceFile*, cmCPluginAPISourceFile*>;
-  using iterator = derived::iterator;
-  using value_type = derived::value_type;
-  cmCPluginAPISourceFileMap() = default;
-  ~cmCPluginAPISourceFileMap()
-  {
-    for (auto const& i : *this) {
-      delete i.second;
-    }
-  }
-  cmCPluginAPISourceFileMap(const cmCPluginAPISourceFileMap&) = delete;
-  cmCPluginAPISourceFileMap& operator=(const cmCPluginAPISourceFileMap&) =
-    delete;
-};
+using cmCPluginAPISourceFileMap =
+  std::map<cmSourceFile*, std::unique_ptr<cmCPluginAPISourceFile>>;
 cmCPluginAPISourceFileMap cmCPluginAPISourceFiles;
 
 void* CCONV cmCreateSourceFile(void)
@@ -536,7 +520,7 @@ void CCONV* cmGetSource(void* arg, const char* name)
     auto i = cmCPluginAPISourceFiles.find(rsf);
     if (i == cmCPluginAPISourceFiles.end()) {
       // Create a proxy source file object for this source.
-      cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
+      auto sf = cm::make_unique<cmCPluginAPISourceFile>();
       sf->RealSourceFile = rsf;
       sf->FullPath = rsf->ResolveFullPath();
       sf->SourceName =
@@ -545,10 +529,9 @@ void CCONV* cmGetSource(void* arg, const char* name)
         cmSystemTools::GetFilenameLastExtension(sf->FullPath);
 
       // Store the proxy in the map so it can be re-used and deleted later.
-      cmCPluginAPISourceFileMap::value_type entry(rsf, sf);
-      i = cmCPluginAPISourceFiles.insert(entry).first;
+      i = cmCPluginAPISourceFiles.emplace(rsf, std::move(sf)).first;
     }
-    return i->second;
+    return i->second.get();
   }
   return nullptr;
 }
@@ -569,15 +552,16 @@ void* CCONV cmAddSource(void* arg, void* arg2)
   }
 
   // Create the proxy for the real source file.
-  cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
+  auto sf = cm::make_unique<cmCPluginAPISourceFile>();
   sf->RealSourceFile = rsf;
   sf->FullPath = osf->FullPath;
   sf->SourceName = osf->SourceName;
   sf->SourceExtension = osf->SourceExtension;
 
   // Store the proxy in the map so it can be re-used and deleted later.
-  cmCPluginAPISourceFiles[rsf] = sf;
-  return sf;
+  auto value = sf.get();
+  cmCPluginAPISourceFiles[rsf] = std::move(sf);
+  return value;
 }
 
 const char* CCONV cmSourceFileGetSourceName(void* arg)

+ 8 - 13
Source/cmCTest.cxx

@@ -16,6 +16,9 @@
 #include <utility>
 #include <vector>
 
+#include <cm/memory>
+#include <cmext/algorithm>
+
 #include "cmsys/Base64.h"
 #include "cmsys/Directory.hxx"
 #include "cmsys/FStream.hxx"
@@ -32,9 +35,6 @@
 #  include <unistd.h> // IWYU pragma: keep
 #endif
 
-#include <cm/memory>
-#include <cmext/algorithm>
-
 #include "cmCTestBuildAndTestHandler.h"
 #include "cmCTestBuildHandler.h"
 #include "cmCTestConfigureHandler.h"
@@ -201,7 +201,7 @@ struct cmCTest::Private
 
   int SubmitIndex = 0;
 
-  cmGeneratedFileStream* OutputLogFile = nullptr;
+  std::unique_ptr<cmGeneratedFileStream> OutputLogFile;
   int OutputLogFileLastTag = -1;
 
   bool OutputTestOutputOnTestFailure = false;
@@ -362,10 +362,7 @@ cmCTest::cmCTest()
   cmSystemTools::EnableVSConsoleOutput();
 }
 
-cmCTest::~cmCTest()
-{
-  delete this->Impl->OutputLogFile;
-}
+cmCTest::~cmCTest() = default;
 
 int cmCTest::GetParallelLevel() const
 {
@@ -3086,12 +3083,10 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
 
 void cmCTest::SetOutputLogFileName(const char* name)
 {
-  if (this->Impl->OutputLogFile) {
-    delete this->Impl->OutputLogFile;
-    this->Impl->OutputLogFile = nullptr;
-  }
   if (name) {
-    this->Impl->OutputLogFile = new cmGeneratedFileStream(name);
+    this->Impl->OutputLogFile = cm::make_unique<cmGeneratedFileStream>(name);
+  } else {
+    this->Impl->OutputLogFile.reset();
   }
 }
 

+ 18 - 18
Source/cmCommandArgumentParserHelper.cxx

@@ -5,6 +5,9 @@
 #include <cstring>
 #include <iostream>
 #include <sstream>
+#include <utility>
+
+#include <cm/memory>
 
 #include "cmCommandArgumentLexer.h"
 #include "cmMakefile.h"
@@ -40,10 +43,10 @@ const char* cmCommandArgumentParserHelper::AddString(const std::string& str)
   if (str.empty()) {
     return "";
   }
-  char* stVal = new char[str.size() + 1];
-  strcpy(stVal, str.c_str());
-  this->Variables.push_back(stVal);
-  return stVal;
+  auto stVal = cm::make_unique<char[]>(str.size() + 1);
+  strcpy(stVal.get(), str.c_str());
+  this->Variables.push_back(std::move(stVal));
+  return this->Variables.back().get();
 }
 
 const char* cmCommandArgumentParserHelper::ExpandSpecialVariable(
@@ -136,11 +139,11 @@ const char* cmCommandArgumentParserHelper::CombineUnions(const char* in1,
     return in1;
   }
   size_t len = strlen(in1) + strlen(in2) + 1;
-  char* out = new char[len];
-  strcpy(out, in1);
-  strcat(out, in2);
-  this->Variables.push_back(out);
-  return out;
+  auto out = cm::make_unique<char[]>(len);
+  strcpy(out.get(), in1);
+  strcat(out.get(), in2);
+  this->Variables.push_back(std::move(out));
+  return this->Variables.back().get();
 }
 
 void cmCommandArgumentParserHelper::AllocateParserType(
@@ -153,11 +156,11 @@ void cmCommandArgumentParserHelper::AllocateParserType(
   if (len == 0) {
     return;
   }
-  char* out = new char[len + 1];
-  memcpy(out, str, len);
-  out[len] = 0;
-  pt->str = out;
-  this->Variables.push_back(out);
+  auto out = cm::make_unique<char[]>(len + 1);
+  memcpy(out.get(), str, len);
+  out.get()[len] = 0;
+  pt->str = out.get();
+  this->Variables.push_back(std::move(out));
 }
 
 bool cmCommandArgumentParserHelper::HandleEscapeSymbol(
@@ -235,10 +238,7 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
 
 void cmCommandArgumentParserHelper::CleanupParser()
 {
-  for (char* var : this->Variables) {
-    delete[] var;
-  }
-  this->Variables.erase(this->Variables.begin(), this->Variables.end());
+  this->Variables.clear();
 }
 
 int cmCommandArgumentParserHelper::LexInput(char* buf, int maxlen)

+ 2 - 1
Source/cmCommandArgumentParserHelper.h

@@ -5,6 +5,7 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -69,7 +70,7 @@ private:
   void CleanupParser();
   void SetError(std::string const& msg);
 
-  std::vector<char*> Variables;
+  std::vector<std::unique_ptr<char[]>> Variables;
   const cmMakefile* Makefile;
   std::string Result;
   std::string ErrorString;

+ 5 - 6
Source/cmDependsJavaParserHelper.cxx

@@ -8,6 +8,7 @@
 #include <iostream>
 #include <utility>
 
+#include <cm/memory>
 #include <cm/string_view>
 
 #include "cmsys/FStream.hxx"
@@ -169,10 +170,11 @@ void cmDependsJavaParserHelper::AllocateParserType(
     return;
   }
   this->UnionsAvailable++;
-  pt->str = new char[len + 1];
+  auto up = cm::make_unique<char[]>(len + 1);
+  pt->str = up.get();
   strncpy(pt->str, str, len);
   pt->str[len] = 0;
-  this->Allocates.push_back(pt->str);
+  this->Allocates.push_back(std::move(up));
 }
 
 void cmDependsJavaParserHelper::StartClass(const char* cls)
@@ -275,10 +277,7 @@ int cmDependsJavaParserHelper::ParseString(const char* str, int verb)
 
 void cmDependsJavaParserHelper::CleanupParser()
 {
-  for (char* allocate : this->Allocates) {
-    delete[] allocate;
-  }
-  this->Allocates.erase(this->Allocates.begin(), this->Allocates.end());
+  this->Allocates.clear();
 }
 
 int cmDependsJavaParserHelper::LexInput(char* buf, int maxlen)

+ 2 - 1
Source/cmDependsJavaParserHelper.h

@@ -5,6 +5,7 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -81,7 +82,7 @@ private:
   int CurrentDepth;
   int Verbose;
 
-  std::vector<char*> Allocates;
+  std::vector<std::unique_ptr<char[]>> Allocates;
 
   void PrintClasses();
 

+ 10 - 12
Source/cmDynamicLoader.cxx

@@ -6,6 +6,7 @@
 #include <string>
 #include <utility>
 
+namespace {
 class cmDynamicLoaderCache
 {
 public:
@@ -15,14 +16,15 @@ public:
                     cmsys::DynamicLoader::LibraryHandle& /*p*/);
   bool FlushCache(const char* path);
   void FlushCache();
-  static cmDynamicLoaderCache* GetInstance();
+  static cmDynamicLoaderCache& GetInstance();
 
 private:
   std::map<std::string, cmsys::DynamicLoader::LibraryHandle> CacheMap;
-  static cmDynamicLoaderCache* Instance;
+  static cmDynamicLoaderCache Instance;
 };
 
-cmDynamicLoaderCache* cmDynamicLoaderCache::Instance = nullptr;
+cmDynamicLoaderCache cmDynamicLoaderCache::Instance;
+}
 
 cmDynamicLoaderCache::~cmDynamicLoaderCache() = default;
 
@@ -64,15 +66,11 @@ void cmDynamicLoaderCache::FlushCache()
   for (auto const& it : this->CacheMap) {
     cmsys::DynamicLoader::CloseLibrary(it.second);
   }
-  delete cmDynamicLoaderCache::Instance;
-  cmDynamicLoaderCache::Instance = nullptr;
+  this->CacheMap.clear();
 }
 
-cmDynamicLoaderCache* cmDynamicLoaderCache::GetInstance()
+cmDynamicLoaderCache& cmDynamicLoaderCache::GetInstance()
 {
-  if (!cmDynamicLoaderCache::Instance) {
-    cmDynamicLoaderCache::Instance = new cmDynamicLoaderCache;
-  }
   return cmDynamicLoaderCache::Instance;
 }
 
@@ -80,15 +78,15 @@ cmsys::DynamicLoader::LibraryHandle cmDynamicLoader::OpenLibrary(
   const char* libname)
 {
   cmsys::DynamicLoader::LibraryHandle lh;
-  if (cmDynamicLoaderCache::GetInstance()->GetCacheFile(libname, lh)) {
+  if (cmDynamicLoaderCache::GetInstance().GetCacheFile(libname, lh)) {
     return lh;
   }
   lh = cmsys::DynamicLoader::OpenLibrary(libname);
-  cmDynamicLoaderCache::GetInstance()->CacheFile(libname, lh);
+  cmDynamicLoaderCache::GetInstance().CacheFile(libname, lh);
   return lh;
 }
 
 void cmDynamicLoader::FlushCache()
 {
-  cmDynamicLoaderCache::GetInstance()->FlushCache();
+  cmDynamicLoaderCache::GetInstance().FlushCache();
 }

+ 7 - 6
Source/cmGlobalUnixMakefileGenerator3.cxx

@@ -41,7 +41,6 @@ cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3(cmake* cm)
 #else
   this->UseLinkScript = true;
 #endif
-  this->CommandDatabase = nullptr;
 
   this->IncludeDirective = "include";
   this->DefineWindowsNULL = false;
@@ -49,6 +48,8 @@ cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3(cmake* cm)
   this->UnixCD = true;
 }
 
+cmGlobalUnixMakefileGenerator3::~cmGlobalUnixMakefileGenerator3() = default;
+
 void cmGlobalUnixMakefileGenerator3::EnableLanguage(
   std::vector<std::string> const& languages, cmMakefile* mf, bool optional)
 {
@@ -157,10 +158,9 @@ void cmGlobalUnixMakefileGenerator3::Generate()
   this->WriteMainMakefile2();
   this->WriteMainCMakefile();
 
-  if (this->CommandDatabase != nullptr) {
+  if (this->CommandDatabase) {
     *this->CommandDatabase << std::endl << "]";
-    delete this->CommandDatabase;
-    this->CommandDatabase = nullptr;
+    this->CommandDatabase.reset();
   }
 }
 
@@ -168,11 +168,12 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
   const std::string& sourceFile, const std::string& workingDirectory,
   const std::string& compileCommand)
 {
-  if (this->CommandDatabase == nullptr) {
+  if (!this->CommandDatabase) {
     std::string commandDatabaseName =
       this->GetCMakeInstance()->GetHomeOutputDirectory() +
       "/compile_commands.json";
-    this->CommandDatabase = new cmGeneratedFileStream(commandDatabaseName);
+    this->CommandDatabase =
+      cm::make_unique<cmGeneratedFileStream>(commandDatabaseName);
     *this->CommandDatabase << "[" << std::endl;
   } else {
     *this->CommandDatabase << "," << std::endl;

+ 8 - 1
Source/cmGlobalUnixMakefileGenerator3.h

@@ -68,6 +68,13 @@ public:
       new cmGlobalGeneratorSimpleFactory<cmGlobalUnixMakefileGenerator3>());
   }
 
+  ~cmGlobalUnixMakefileGenerator3() override;
+
+  cmGlobalUnixMakefileGenerator3(const cmGlobalUnixMakefileGenerator3&) =
+    delete;
+  cmGlobalUnixMakefileGenerator3& operator=(
+    const cmGlobalUnixMakefileGenerator3&) = delete;
+
   //! Get the name for the generator.
   std::string GetName() const override
   {
@@ -232,7 +239,7 @@ protected:
     std::set<cmGeneratorTarget const*>& emitted);
   size_t CountProgressMarksInAll(const cmLocalGenerator& lg);
 
-  cmGeneratedFileStream* CommandDatabase;
+  std::unique_ptr<cmGeneratedFileStream> CommandDatabase;
 
 private:
   const char* GetBuildIgnoreErrorsFlag() const override { return "-i"; }

+ 5 - 6
Source/cmInstallExportGenerator.cxx

@@ -7,6 +7,8 @@
 #include <sstream>
 #include <utility>
 
+#include <cm/memory>
+
 #ifndef CMAKE_BOOTSTRAP
 #  include "cmExportInstallAndroidMKGenerator.h"
 #endif
@@ -33,18 +35,15 @@ cmInstallExportGenerator::cmInstallExportGenerator(
 {
   if (android) {
 #ifndef CMAKE_BOOTSTRAP
-    this->EFGen = new cmExportInstallAndroidMKGenerator(this);
+    this->EFGen = cm::make_unique<cmExportInstallAndroidMKGenerator>(this);
 #endif
   } else {
-    this->EFGen = new cmExportInstallFileGenerator(this);
+    this->EFGen = cm::make_unique<cmExportInstallFileGenerator>(this);
   }
   exportSet->AddInstallation(this);
 }
 
-cmInstallExportGenerator::~cmInstallExportGenerator()
-{
-  delete this->EFGen;
-}
+cmInstallExportGenerator::~cmInstallExportGenerator() = default;
 
 bool cmInstallExportGenerator::Compute(cmLocalGenerator* lg)
 {

+ 6 - 1
Source/cmInstallExportGenerator.h

@@ -7,6 +7,7 @@
 
 #include <cstddef>
 #include <iosfwd>
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -30,8 +31,12 @@ public:
                            bool exclude_from_all, std::string filename,
                            std::string name_space, bool exportOld,
                            bool android);
+  cmInstallExportGenerator(const cmInstallExportGenerator&) = delete;
   ~cmInstallExportGenerator() override;
 
+  cmInstallExportGenerator& operator=(const cmInstallExportGenerator&) =
+    delete;
+
   cmExportSet* GetExportSet() { return this->ExportSet; }
 
   bool Compute(cmLocalGenerator* lg) override;
@@ -61,7 +66,7 @@ protected:
 
   std::string TempDir;
   std::string MainImportFile;
-  cmExportInstallFileGenerator* EFGen;
+  std::unique_ptr<cmExportInstallFileGenerator> EFGen;
 };
 
 #endif

+ 15 - 16
Source/cmMachO.cxx

@@ -79,14 +79,14 @@ public:
   // A load_command and its associated data
   struct RawLoadCommand
   {
-    uint32_t type(const cmMachOHeaderAndLoadCommands* m) const
+    uint32_t type(const cmMachOHeaderAndLoadCommands& m) const
     {
       if (this->LoadCommand.size() < sizeof(load_command)) {
         return 0;
       }
       const load_command* cmd =
         reinterpret_cast<const load_command*>(&this->LoadCommand[0]);
-      return m->swap(cmd->cmd);
+      return m.swap(cmd->cmd);
     }
     std::vector<char> LoadCommand;
   };
@@ -186,8 +186,11 @@ class cmMachOInternal
 {
 public:
   cmMachOInternal(const char* fname);
+  cmMachOInternal(const cmMachOInternal&) = delete;
   ~cmMachOInternal();
 
+  cmMachOInternal& operator=(const cmMachOInternal&) = delete;
+
   // read a Mach-O file
   bool read_mach_o(uint32_t file_offset);
 
@@ -202,7 +205,7 @@ public:
   std::string ErrorMessage;
 
   // the list of Mach-O's
-  std::vector<cmMachOHeaderAndLoadCommands*> MachOList;
+  std::vector<std::unique_ptr<cmMachOHeaderAndLoadCommands>> MachOList;
 };
 
 cmMachOInternal::cmMachOInternal(const char* fname)
@@ -260,12 +263,7 @@ cmMachOInternal::cmMachOInternal(const char* fname)
   }
 }
 
-cmMachOInternal::~cmMachOInternal()
-{
-  for (auto& i : this->MachOList) {
-    delete i;
-  }
-}
+cmMachOInternal::~cmMachOInternal() = default;
 
 bool cmMachOInternal::read_mach_o(uint32_t file_offset)
 {
@@ -280,25 +278,25 @@ bool cmMachOInternal::read_mach_o(uint32_t file_offset)
     return false;
   }
 
-  cmMachOHeaderAndLoadCommands* f = nullptr;
+  std::unique_ptr<cmMachOHeaderAndLoadCommands> f;
   if (magic == MH_CIGAM || magic == MH_MAGIC) {
     bool swap = false;
     if (magic == MH_CIGAM) {
       swap = true;
     }
-    f = new cmMachOHeaderAndLoadCommandsImpl<mach_header>(swap);
+    f = cm::make_unique<cmMachOHeaderAndLoadCommandsImpl<mach_header>>(swap);
   } else if (magic == MH_CIGAM_64 || magic == MH_MAGIC_64) {
     bool swap = false;
     if (magic == MH_CIGAM_64) {
       swap = true;
     }
-    f = new cmMachOHeaderAndLoadCommandsImpl<mach_header_64>(swap);
+    f =
+      cm::make_unique<cmMachOHeaderAndLoadCommandsImpl<mach_header_64>>(swap);
   }
 
   if (f && f->read_mach_o(this->Fin)) {
-    this->MachOList.push_back(f);
+    this->MachOList.push_back(std::move(f));
   } else {
-    delete f;
     this->ErrorMessage = "Failed to read Mach-O header.";
     return false;
   }
@@ -333,11 +331,12 @@ bool cmMachO::GetInstallName(std::string& install_name)
   }
 
   // grab the first Mach-O and get the install name from that one
-  cmMachOHeaderAndLoadCommands* macho = this->Internal->MachOList[0];
+  std::unique_ptr<cmMachOHeaderAndLoadCommands>& macho =
+    this->Internal->MachOList[0];
   for (size_t i = 0; i < macho->load_commands().size(); i++) {
     const cmMachOHeaderAndLoadCommands::RawLoadCommand& cmd =
       macho->load_commands()[i];
-    uint32_t lc_cmd = cmd.type(macho);
+    uint32_t lc_cmd = cmd.type(*macho);
     if (lc_cmd == LC_ID_DYLIB || lc_cmd == LC_LOAD_WEAK_DYLIB ||
         lc_cmd == LC_LOAD_DYLIB) {
       if (sizeof(dylib_command) < cmd.LoadCommand.size()) {

+ 14 - 17
Source/cmServer.cxx

@@ -59,16 +59,12 @@ cmServer::cmServer(cmConnection* conn, bool supportExperimental)
   , SupportExperimental(supportExperimental)
 {
   // Register supported protocols:
-  this->RegisterProtocol(new cmServerProtocol1);
+  this->RegisterProtocol(cm::make_unique<cmServerProtocol1>());
 }
 
 cmServer::~cmServer()
 {
   Close();
-
-  for (cmServerProtocol* p : this->SupportedProtocols) {
-    delete p;
-  }
 }
 
 void cmServer::ProcessRequest(cmConnection* connection,
@@ -117,22 +113,22 @@ void cmServer::ProcessRequest(cmConnection* connection,
   }
 }
 
-void cmServer::RegisterProtocol(cmServerProtocol* protocol)
+void cmServer::RegisterProtocol(std::unique_ptr<cmServerProtocol> protocol)
 {
   if (protocol->IsExperimental() && !this->SupportExperimental) {
-    delete protocol;
+    protocol.reset();
     return;
   }
   auto version = protocol->ProtocolVersion();
   assert(version.first >= 0);
   assert(version.second >= 0);
-  auto it = std::find_if(this->SupportedProtocols.begin(),
-                         this->SupportedProtocols.end(),
-                         [version](cmServerProtocol* p) {
-                           return p->ProtocolVersion() == version;
-                         });
+  auto it = std::find_if(
+    this->SupportedProtocols.begin(), this->SupportedProtocols.end(),
+    [version](const std::unique_ptr<cmServerProtocol>& p) {
+      return p->ProtocolVersion() == version;
+    });
   if (it == this->SupportedProtocols.end()) {
-    this->SupportedProtocols.push_back(protocol);
+    this->SupportedProtocols.push_back(std::move(protocol));
   }
 }
 
@@ -297,19 +293,20 @@ void cmServer::WriteJsonObject(cmConnection* connection,
 }
 
 cmServerProtocol* cmServer::FindMatchingProtocol(
-  const std::vector<cmServerProtocol*>& protocols, int major, int minor)
+  const std::vector<std::unique_ptr<cmServerProtocol>>& protocols, int major,
+  int minor)
 {
   cmServerProtocol* bestMatch = nullptr;
-  for (auto protocol : protocols) {
+  for (const auto& protocol : protocols) {
     auto version = protocol->ProtocolVersion();
     if (major != version.first) {
       continue;
     }
     if (minor == version.second) {
-      return protocol;
+      return protocol.get();
     }
     if (!bestMatch || bestMatch->ProtocolVersion().second < version.second) {
-      bestMatch = protocol;
+      bestMatch = protocol.get();
     }
   }
   return minor < 0 ? bestMatch : nullptr;

+ 4 - 3
Source/cmServer.h

@@ -103,7 +103,7 @@ public:
   cmFileMonitor* FileMonitor() const;
 
 private:
-  void RegisterProtocol(cmServerProtocol* protocol);
+  void RegisterProtocol(std::unique_ptr<cmServerProtocol> protocol);
 
   // Callbacks from cmServerConnection:
 
@@ -149,12 +149,13 @@ private:
                        const DebugInfo* debug) const;
 
   static cmServerProtocol* FindMatchingProtocol(
-    const std::vector<cmServerProtocol*>& protocols, int major, int minor);
+    const std::vector<std::unique_ptr<cmServerProtocol>>& protocols, int major,
+    int minor);
 
   const bool SupportExperimental;
 
   cmServerProtocol* Protocol = nullptr;
-  std::vector<cmServerProtocol*> SupportedProtocols;
+  std::vector<std::unique_ptr<cmServerProtocol>> SupportedProtocols;
 
   friend class cmServerProtocol;
   friend class cmServerRequest;

+ 5 - 6
Source/cmSourceGroup.cxx

@@ -4,6 +4,8 @@
 
 #include <utility>
 
+#include <cm/memory>
+
 #include "cmStringAlgorithms.h"
 
 class cmSourceGroupInternals
@@ -16,7 +18,7 @@ cmSourceGroup::cmSourceGroup(std::string name, const char* regex,
                              const char* parentName)
   : Name(std::move(name))
 {
-  this->Internal = new cmSourceGroupInternals;
+  this->Internal = cm::make_unique<cmSourceGroupInternals>();
   this->SetGroupRegex(regex);
   if (parentName) {
     this->FullName = cmStrCat(parentName, '\\');
@@ -24,10 +26,7 @@ cmSourceGroup::cmSourceGroup(std::string name, const char* regex,
   this->FullName += this->Name;
 }
 
-cmSourceGroup::~cmSourceGroup()
-{
-  delete this->Internal;
-}
+cmSourceGroup::~cmSourceGroup() = default;
 
 cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
 {
@@ -36,7 +35,7 @@ cmSourceGroup::cmSourceGroup(cmSourceGroup const& r)
   this->GroupRegex = r.GroupRegex;
   this->GroupFiles = r.GroupFiles;
   this->SourceFiles = r.SourceFiles;
-  this->Internal = new cmSourceGroupInternals(*r.Internal);
+  this->Internal = cm::make_unique<cmSourceGroupInternals>(*r.Internal);
 }
 
 cmSourceGroup& cmSourceGroup::operator=(cmSourceGroup const& r)

+ 2 - 1
Source/cmSourceGroup.h

@@ -5,6 +5,7 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
+#include <memory>
 #include <set>
 #include <string>
 #include <vector>
@@ -122,7 +123,7 @@ private:
    */
   std::vector<const cmSourceFile*> SourceFiles;
 
-  cmSourceGroupInternals* Internal;
+  std::unique_ptr<cmSourceGroupInternals> Internal;
 };
 
 #endif

+ 6 - 5
Source/cmSystemTools.cxx

@@ -25,6 +25,9 @@
 #endif
 
 #if !defined(CMAKE_BOOTSTRAP)
+#  if defined(_WIN32)
+#    include <cm/memory>
+#  endif
 #  include "cmCryptoHash.h"
 #endif
 
@@ -908,7 +911,6 @@ std::string cmSystemTools::ComputeCertificateThumbprint(
   std::string thumbprint;
 
 #if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32)
-  BYTE* certData = NULL;
   CRYPT_INTEGER_BLOB cryptBlob;
   HCERTSTORE certStore = NULL;
   PCCERT_CONTEXT certContext = NULL;
@@ -920,12 +922,12 @@ std::string cmSystemTools::ComputeCertificateThumbprint(
   if (certFile != INVALID_HANDLE_VALUE && certFile != NULL) {
     DWORD fileSize = GetFileSize(certFile, NULL);
     if (fileSize != INVALID_FILE_SIZE) {
-      certData = new BYTE[fileSize];
+      auto certData = cm::make_unique<BYTE[]>(fileSize);
       if (certData != NULL) {
         DWORD dwRead = 0;
-        if (ReadFile(certFile, certData, fileSize, &dwRead, NULL)) {
+        if (ReadFile(certFile, certData.get(), fileSize, &dwRead, NULL)) {
           cryptBlob.cbData = fileSize;
-          cryptBlob.pbData = certData;
+          cryptBlob.pbData = certData.get();
 
           // Verify that this is a valid cert
           if (PFXIsPFXBlob(&cryptBlob)) {
@@ -961,7 +963,6 @@ std::string cmSystemTools::ComputeCertificateThumbprint(
             }
           }
         }
-        delete[] certData;
       }
     }
     CloseHandle(certFile);