瀏覽代碼

BUG: clean up memory leaks.

Bill Hoffman 24 年之前
父節點
當前提交
a3cfcd9894

+ 12 - 0
Source/MFCDialog/CMakeSetupDialog.cpp

@@ -219,6 +219,17 @@ int CALLBACK CMakeSetupDialog_SetSelProc( HWND hWnd, UINT uMsg,
   return 0;
 }
 
+inline void ILFree(LPITEMIDLIST pidl)
+{
+  LPMALLOC pMalloc;     
+  if (pidl)     
+    { 
+    SHGetMalloc(&pMalloc); 
+    pMalloc->Free( pidl);
+    pMalloc->Release();  
+    }
+}
+
 
 // Browse button
 bool CMakeSetupDialog::Browse(CString &result, const char *title)
@@ -243,6 +254,7 @@ bool CMakeSetupDialog::Browse(CString &result, const char *title)
     {
     result = szPathName;
     }
+  ILFree(pidl);
   return bSuccess;
 }
 

+ 12 - 0
Source/cmCacheManager.cxx

@@ -70,12 +70,24 @@ cmCacheManager::CacheEntryType cmCacheManager::StringToType(const char* s)
 }
 
     
+struct CleanUpCacheManager
+{
+  ~CleanUpCacheManager()
+  {
+    delete cmCacheManager::GetInstance();
+  }
+  void Use() {}
+};
+
+CleanUpCacheManager cleanup;
+
 cmCacheManager* cmCacheManager::s_Instance = 0;
 
 cmCacheManager* cmCacheManager::GetInstance()
 {
   if(!cmCacheManager::s_Instance)
     {
+    cleanup.Use();
     cmCacheManager::s_Instance = new cmCacheManager;
     }
   return cmCacheManager::s_Instance;

+ 12 - 3
Source/cmDSWMakefile.cxx

@@ -96,7 +96,6 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
   // add a special target that depends on ALL projects for easy build
   // of Debug only
   m_Makefile->AddUtilityCommand("ALL_BUILD", "echo \"Build all projects\"", false);
-  
   m_Makefile->FindSubDirectoryCMakeListsFiles(allListFiles);
   // For each cmMakefile, create a DSP for it, and
   // add it to this DSW file
@@ -104,8 +103,18 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
       k != allListFiles.end(); ++k)
     {
     cmMakefile* mf = *k;
-    // Create an MS generator with DSW off, so it only creates dsp files
-    cmMSProjectGenerator* pg = new cmMSProjectGenerator;
+    cmMSProjectGenerator* pg = 0;
+    // if not this makefile, then create a new generator
+    if(m_Makefile != mf)
+      {
+      // Create an MS generator with DSW off, so it only creates dsp files
+      pg = new cmMSProjectGenerator;
+      }
+    else
+      {
+      pg = (cmMSProjectGenerator*)m_Makefile->GetMakefileGenerator();
+      }
+    // make sure the generator is building dsp files
     pg->BuildDSWOff();
     mf->SetMakefileGenerator(pg);
     mf->GenerateMakefile();

+ 12 - 3
Source/cmDSWWriter.cxx

@@ -96,7 +96,6 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
   // add a special target that depends on ALL projects for easy build
   // of Debug only
   m_Makefile->AddUtilityCommand("ALL_BUILD", "echo \"Build all projects\"", false);
-  
   m_Makefile->FindSubDirectoryCMakeListsFiles(allListFiles);
   // For each cmMakefile, create a DSP for it, and
   // add it to this DSW file
@@ -104,8 +103,18 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
       k != allListFiles.end(); ++k)
     {
     cmMakefile* mf = *k;
-    // Create an MS generator with DSW off, so it only creates dsp files
-    cmMSProjectGenerator* pg = new cmMSProjectGenerator;
+    cmMSProjectGenerator* pg = 0;
+    // if not this makefile, then create a new generator
+    if(m_Makefile != mf)
+      {
+      // Create an MS generator with DSW off, so it only creates dsp files
+      pg = new cmMSProjectGenerator;
+      }
+    else
+      {
+      pg = (cmMSProjectGenerator*)m_Makefile->GetMakefileGenerator();
+      }
+    // make sure the generator is building dsp files
     pg->BuildDSWOff();
     mf->SetMakefileGenerator(pg);
     mf->GenerateMakefile();

+ 2 - 0
Source/cmFunctionBlocker.h

@@ -72,6 +72,8 @@ public:
    * regular CMakeList file 
    */
   virtual void ScopeEnded(const cmMakefile &mf) const {}
+
+  virtual ~cmFunctionBlocker() {}
 };
 
 #endif

+ 4 - 0
Source/cmMSProjectGenerator.cxx

@@ -54,11 +54,15 @@ void cmMSProjectGenerator::GenerateMakefile()
 {
   if(m_BuildDSW)
     {
+    delete m_DSWMakefile;
+    m_DSWMakefile = 0;
     m_DSWMakefile = new cmDSWMakefile(m_Makefile);
     m_DSWMakefile->OutputDSWFile();
     }
   else
     {
+    delete m_DSPMakefile;
+    m_DSPMakefile = 0;
     m_DSPMakefile = new cmDSPMakefile(m_Makefile);
     m_DSPMakefile->OutputDSPFile();
     }

+ 19 - 2
Source/cmMakefile.cxx

@@ -111,6 +111,14 @@ cmMakefile::~cmMakefile()
       delete d->second;
       }
     }
+  std::set<cmFunctionBlocker *>::const_iterator pos;
+  for (pos = m_FunctionBlockers.begin(); 
+       pos != m_FunctionBlockers.end(); ++pos)
+    {
+    cmFunctionBlocker* b = *pos;
+    m_FunctionBlockers.erase(*pos);
+    delete b;
+    }
   delete m_MakefileGenerator;
 }
 
@@ -189,7 +197,10 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
   // keep track of the current file being read
   if (filename)
     {
-    m_cmCurrentListFile= filename;
+    if(m_cmCurrentListFile != filename)
+      {
+      m_cmCurrentListFile = filename;
+      }
     }
 
   // if this is not a remote makefile
@@ -342,6 +353,10 @@ void cmMakefile::AddCommand(cmCommand* wg)
   // Set the make file 
 void cmMakefile::SetMakefileGenerator(cmMakefileGenerator* mf)
 {
+  if(mf == m_MakefileGenerator)
+  {
+    return;
+  }
   delete m_MakefileGenerator;
   m_MakefileGenerator = mf;
   mf->SetMakefile(this);
@@ -836,7 +851,7 @@ bool cmMakefile::IsFunctionBlocked(const char *name,
 }
 
 void cmMakefile::RemoveFunctionBlocker(const char *name,
-								       const std::vector<std::string> &args)
+				       const std::vector<std::string> &args)
 {
   // loop over all function blockers to see if any block this command
   std::set<cmFunctionBlocker *>::const_iterator pos;
@@ -845,7 +860,9 @@ void cmMakefile::RemoveFunctionBlocker(const char *name,
     {
     if ((*pos)->ShouldRemove(name, args, *this))
       {
+      cmFunctionBlocker* b = *pos;
       m_FunctionBlockers.erase(*pos);
+      delete b;
       return;
       }
     }

+ 1 - 0
Source/cmMakefileGenerator.h

@@ -82,6 +82,7 @@ public:
    */
   virtual void ComputeSystemInfo() = 0;
 
+  virtual ~cmMakefileGenerator(){};
 protected:
   cmMakefile* m_Makefile;
 };