diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2019-01-11 21:31:52 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2019-01-14 14:53:12 (GMT) |
commit | 613323a78bf33e22f510e41c8733fe2bc8df606a (patch) | |
tree | e4631cdd35d74319c894334626c27b7b5fd1497c /Source | |
parent | bf2503089b19d1462be7838ed7364361481587d4 (diff) | |
download | CMake-613323a78bf33e22f510e41c8733fe2bc8df606a.zip CMake-613323a78bf33e22f510e41c8733fe2bc8df606a.tar.gz CMake-613323a78bf33e22f510e41c8733fe2bc8df606a.tar.bz2 |
cmGlobalUnixMakefileGenerator3: Fix memory leak warning
this->Makefiles.empty() is called twice, leading clang scan-build
to falsely believe that the delete statement was causing a memory
leak. Fix this by using a unique_ptr to hold the temporary
cmMakefile. This also has the benefit of making the code
exception-safe.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.cxx | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index db72353..ceee500 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -7,6 +7,7 @@ #include <sstream> #include <utility> +#include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" @@ -494,6 +495,7 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( const std::string& targetName, const std::string& /*config*/, bool fast, int jobs, bool /*verbose*/, std::vector<std::string> const& makeOptions) { + std::unique_ptr<cmMakefile> mfu; cmMakefile* mf; if (!this->Makefiles.empty()) { mf = this->Makefiles[0]; @@ -504,7 +506,8 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( snapshot.GetDirectory().SetCurrentBinary( this->CMakeInstance->GetHomeOutputDirectory()); snapshot.SetDefaultDefinitions(); - mf = new cmMakefile(this, snapshot); + mfu = cm::make_unique<cmMakefile>(this, snapshot); + mf = mfu.get(); } makeCommand.push_back(this->SelectMakeProgram(makeProgram)); @@ -529,9 +532,6 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( cmSystemTools::ConvertToOutputSlashes(tname); makeCommand.push_back(std::move(tname)); } - if (this->Makefiles.empty()) { - delete mf; - } } void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules( |