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.
This commit is contained in:
Kyle Edwards 2019-01-11 16:31:52 -05:00
parent bf2503089b
commit 613323a78b

View File

@ -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(