Prevent memory leaks in case SeqILU0 throws an exception.

This commit is contained in:
Markus Blatt
2015-09-08 14:38:29 +02:00
parent 3c1498ce92
commit 32b8ed654e
2 changed files with 11 additions and 1 deletions

View File

@@ -196,6 +196,11 @@ createILU0Ptr(const M& A, double relax,
// Check whether there was a problem on some process
if ( comm.communicator().min(ilu_setup_successful) == 0 )
{
if ( ilu ) // not null if constructor succeeded
{
// prevent memory leak
delete ilu;
}
throw Dune::MatrixBlockError();
}
return typename SelectParallelILUSharedPtr<Dune::SeqILU0<M,X,X>, I1, I2>

View File

@@ -139,7 +139,7 @@ namespace Opm
const double relax = 1.0;
SeqPreconditioner* seq_precond = nullptr;
try {
seq_precond= new SeqPreconditioner(opA.getmat(),
seq_precond = new SeqPreconditioner(opA.getmat(),
relax);
}
catch ( Dune::MatrixBlockError error )
@@ -154,6 +154,11 @@ namespace Opm
// Check whether there was a problem on some process
if ( comm.communicator().min(ilu_setup_successful) == 0 )
{
if ( seq_precond ) // not null if constructor succeeded
{
// prevent memory leak
delete seq_precond;
}
throw Dune::MatrixBlockError();
}
return Pointer(new ParPreconditioner(*seq_precond, comm),