BUG: clean up memory leaks.

This commit is contained in:
Bill Hoffman 2001-06-04 10:18:03 -04:00
parent abab6bc000
commit a3cfcd9894
8 changed files with 74 additions and 8 deletions

View File

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

View File

@ -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::s_Instance = 0;
cmCacheManager* cmCacheManager::GetInstance() cmCacheManager* cmCacheManager::GetInstance()
{ {
if(!cmCacheManager::s_Instance) if(!cmCacheManager::s_Instance)
{ {
cleanup.Use();
cmCacheManager::s_Instance = new cmCacheManager; cmCacheManager::s_Instance = new cmCacheManager;
} }
return cmCacheManager::s_Instance; return cmCacheManager::s_Instance;

View File

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

View File

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

View File

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

View File

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

View File

@ -111,6 +111,14 @@ cmMakefile::~cmMakefile()
delete d->second; 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; delete m_MakefileGenerator;
} }
@ -189,7 +197,10 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
// keep track of the current file being read // keep track of the current file being read
if (filename) if (filename)
{ {
m_cmCurrentListFile= filename; if(m_cmCurrentListFile != filename)
{
m_cmCurrentListFile = filename;
}
} }
// if this is not a remote makefile // if this is not a remote makefile
@ -342,6 +353,10 @@ void cmMakefile::AddCommand(cmCommand* wg)
// Set the make file // Set the make file
void cmMakefile::SetMakefileGenerator(cmMakefileGenerator* mf) void cmMakefile::SetMakefileGenerator(cmMakefileGenerator* mf)
{ {
if(mf == m_MakefileGenerator)
{
return;
}
delete m_MakefileGenerator; delete m_MakefileGenerator;
m_MakefileGenerator = mf; m_MakefileGenerator = mf;
mf->SetMakefile(this); mf->SetMakefile(this);
@ -845,7 +860,9 @@ void cmMakefile::RemoveFunctionBlocker(const char *name,
{ {
if ((*pos)->ShouldRemove(name, args, *this)) if ((*pos)->ShouldRemove(name, args, *this))
{ {
cmFunctionBlocker* b = *pos;
m_FunctionBlockers.erase(*pos); m_FunctionBlockers.erase(*pos);
delete b;
return; return;
} }
} }

View File

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