From a3cfcd9894a5d626b8beba80fc8b5934ea3f46cf Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 4 Jun 2001 10:18:03 -0400 Subject: [PATCH] BUG: clean up memory leaks. --- Source/MFCDialog/CMakeSetupDialog.cpp | 12 ++++++++++++ Source/cmCacheManager.cxx | 12 ++++++++++++ Source/cmDSWMakefile.cxx | 15 ++++++++++++--- Source/cmDSWWriter.cxx | 15 ++++++++++++--- Source/cmFunctionBlocker.h | 2 ++ Source/cmMSProjectGenerator.cxx | 4 ++++ Source/cmMakefile.cxx | 21 +++++++++++++++++++-- Source/cmMakefileGenerator.h | 1 + 8 files changed, 74 insertions(+), 8 deletions(-) diff --git a/Source/MFCDialog/CMakeSetupDialog.cpp b/Source/MFCDialog/CMakeSetupDialog.cpp index 0505e504c..d6819eb4f 100644 --- a/Source/MFCDialog/CMakeSetupDialog.cpp +++ b/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; } diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index d183e2301..b28ec3e02 100644 --- a/Source/cmCacheManager.cxx +++ b/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; diff --git a/Source/cmDSWMakefile.cxx b/Source/cmDSWMakefile.cxx index cd3feb777..082386923 100644 --- a/Source/cmDSWMakefile.cxx +++ b/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(); diff --git a/Source/cmDSWWriter.cxx b/Source/cmDSWWriter.cxx index cd3feb777..082386923 100644 --- a/Source/cmDSWWriter.cxx +++ b/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(); diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h index 5c8c70d29..3891ff106 100644 --- a/Source/cmFunctionBlocker.h +++ b/Source/cmFunctionBlocker.h @@ -72,6 +72,8 @@ public: * regular CMakeList file */ virtual void ScopeEnded(const cmMakefile &mf) const {} + + virtual ~cmFunctionBlocker() {} }; #endif diff --git a/Source/cmMSProjectGenerator.cxx b/Source/cmMSProjectGenerator.cxx index 12e2733d2..7ac41062d 100644 --- a/Source/cmMSProjectGenerator.cxx +++ b/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(); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 134fdf93d..446729ea6 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -111,6 +111,14 @@ cmMakefile::~cmMakefile() delete d->second; } } + std::set::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 &args) + const std::vector &args) { // loop over all function blockers to see if any block this command std::set::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; } } diff --git a/Source/cmMakefileGenerator.h b/Source/cmMakefileGenerator.h index a44e62b72..688d31f4e 100644 --- a/Source/cmMakefileGenerator.h +++ b/Source/cmMakefileGenerator.h @@ -82,6 +82,7 @@ public: */ virtual void ComputeSystemInfo() = 0; + virtual ~cmMakefileGenerator(){}; protected: cmMakefile* m_Makefile; };