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:
@@ -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");
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user