From 0842958977ce9037cf597871df6baf72736c7973 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Sun, 8 May 2005 13:48:09 -0400 Subject: [PATCH] ENH: Remove memory leak and remember global generator for next time --- Source/CTest/cmCTestBuildCommand.cxx | 41 ++++++++++++++++++++++++---- Source/CTest/cmCTestBuildCommand.h | 7 ++++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index d8f1ef7bc..481215228 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -21,6 +21,24 @@ #include "cmake.h" #include "cmGlobalGenerator.h" + +//---------------------------------------------------------------------------- +cmCTestBuildCommand::cmCTestBuildCommand() +{ + m_GlobalGenerator = 0; +} + +//---------------------------------------------------------------------------- +cmCTestBuildCommand::~cmCTestBuildCommand() +{ + if ( m_GlobalGenerator ) + { + delete m_GlobalGenerator; + m_GlobalGenerator = 0; + } +} + +//---------------------------------------------------------------------------- bool cmCTestBuildCommand::InitialPass( std::vector const& args) { @@ -97,13 +115,24 @@ bool cmCTestBuildCommand::InitialPass( { cmakeBuildConfiguration = "Release"; } - cmGlobalGenerator* gen = - m_Makefile->GetCMakeInstance()->CreateGlobalGenerator(cmakeGeneratorName); - gen->FindMakeProgram(m_Makefile); + if ( m_GlobalGenerator ) + { + if ( strcmp(m_GlobalGenerator->GetName(), cmakeGeneratorName) != 0 ) + { + delete m_GlobalGenerator; + m_GlobalGenerator = 0; + } + } + if ( !m_GlobalGenerator ) + { + m_GlobalGenerator = + m_Makefile->GetCMakeInstance()->CreateGlobalGenerator(cmakeGeneratorName); + } + m_GlobalGenerator->FindMakeProgram(m_Makefile); const char* cmakeMakeProgram = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM"); - std::string buildCommand = gen->GenerateBuildCommand(cmakeMakeProgram, cmakeProjectName, - 0, cmakeBuildConfiguration, true); - + std::string buildCommand + = m_GlobalGenerator->GenerateBuildCommand(cmakeMakeProgram, cmakeProjectName, + 0, cmakeBuildConfiguration, true); m_CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str()); } else diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h index 4284a0813..06078630b 100644 --- a/Source/CTest/cmCTestBuildCommand.h +++ b/Source/CTest/cmCTestBuildCommand.h @@ -19,6 +19,8 @@ #include "cmCTestCommand.h" +class cmGlobalGenerator; + /** \class cmCTestBuild * \brief Run a ctest script * @@ -28,7 +30,8 @@ class cmCTestBuildCommand : public cmCTestCommand { public: - cmCTestBuildCommand() {} + cmCTestBuildCommand(); + ~cmCTestBuildCommand(); /** * This is a virtual constructor for the command. @@ -71,6 +74,8 @@ public: } cmTypeMacro(cmCTestBuildCommand, cmCTestCommand); + + cmGlobalGenerator* m_GlobalGenerator; };