Avoid leaking the MPSolver object in some samples

In samples using MPSolver::CreateSolver(), track the resulting solver
with a std::unique_ptr to avoid leaking it.

Fix #2411
This commit is contained in:
Hugues Evrard
2021-02-24 21:19:08 +00:00
committed by Mizux
parent ef0ceb8128
commit 08abcea750
4 changed files with 4 additions and 4 deletions

View File

@@ -132,7 +132,7 @@ void RunBooleanProgrammingExample(
void MutableObjectiveCrash() {
LOG(INFO) << "MutableObjectiveCrash";
// Create the linear solver with the GLOP backend.
MPSolver* solver = MPSolver::CreateSolver("GLOP");
std::unique_ptr<MPSolver> solver(MPSolver::CreateSolver("GLOP"));
// Create the variables x and y.
MPVariable* const x = solver->MakeNumVar(0.0, 1, "x");

View File

@@ -21,7 +21,7 @@ namespace operations_research {
void BasicExample() {
// [START solver]
// Create the linear solver with the GLOP backend.
MPSolver* solver = MPSolver::CreateSolver("GLOP");
std::unique_ptr<MPSolver> solver(MPSolver::CreateSolver("GLOP"));
// [END solver]
// [START variables]

View File

@@ -21,7 +21,7 @@ namespace operations_research {
void SimpleLpProgram() {
// [START solver]
// Create the linear solver with the GLOP backend.
MPSolver* solver = MPSolver::CreateSolver("GLOP");
std::unique_ptr<MPSolver> solver(MPSolver::CreateSolver("GLOP"));
// [END solver]
// [START variables]

View File

@@ -21,7 +21,7 @@ namespace operations_research {
void SimpleMipProgram() {
// [START solver]
// Create the mip solver with the SCIP backend.
MPSolver* solver = MPSolver::CreateSolver("SCIP");
std::unique_ptr<MPSolver> solver(MPSolver::CreateSolver("SCIP"));
// [END solver]
// [START variables]