Avoid memory leak from the *unique_ptr<X>.release() antipattern.

This commit is contained in:
Atgeirr Flø Rasmussen 2024-05-28 16:49:08 +02:00
parent c84f14042d
commit 6a7e1e08c0
5 changed files with 10 additions and 8 deletions

View File

@ -174,8 +174,8 @@ public:
const UDQState& udqState() const
{ return *udqState_; }
WellTestState transferWTestState() {
return *this->wtestState_.release();
std::unique_ptr<WellTestState> transferWTestState() {
return std::move(this->wtestState_);
}

View File

@ -186,7 +186,7 @@ getWellEcl(const std::string& well_name) const
template<class Scalar>
void BlackoilWellModelGeneric<Scalar>::
initFromRestartFile(const RestartValue& restartValues,
WellTestState wtestState,
std::unique_ptr<WellTestState> wtestState,
const std::size_t numCells,
bool handle_ms_well)
{

View File

@ -156,7 +156,7 @@ public:
const SummaryState& st);
void initFromRestartFile(const RestartValue& restartValues,
WellTestState wtestState,
std::unique_ptr<WellTestState> wtestState,
const std::size_t numCells,
bool handle_ms_well);

View File

@ -46,10 +46,10 @@ serializationTestObject(const ParallelWellInfo<Scalar>& pinfo)
}
template<class Scalar>
void WGState<Scalar>::wtest_state(WellTestState wtest_state)
void WGState<Scalar>::wtest_state(std::unique_ptr<WellTestState> wtest_state)
{
wtest_state.filter_wells( this->well_state.wells() );
this->well_test_state = std::move(wtest_state);
wtest_state->filter_wells( this->well_state.wells() );
this->well_test_state = std::move(*wtest_state);
}
template<class Scalar>

View File

@ -24,6 +24,8 @@
#include <opm/simulators/wells/GroupState.hpp>
#include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
#include <memory>
namespace Opm {
template<class Scalar> class ParallelWellInfo;
@ -41,7 +43,7 @@ struct WGState
static WGState serializationTestObject(const ParallelWellInfo<Scalar>& pinfo);
void wtest_state(WellTestState wtest_state);
void wtest_state(std::unique_ptr<WellTestState> wtest_state);
WellState<Scalar> well_state;
GroupState<Scalar> group_state;