Merge pull request #5394 from atgeirr/avoid-memory-leak

Avoid memory leak from the *unique_ptr<X>.release() antipattern.
This commit is contained in:
Bård Skaflestad 2024-05-28 18:15:01 +02:00 committed by GitHub
commit 03e8c7ecdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 8 deletions

View File

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

View File

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

View File

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

View File

@ -46,10 +46,10 @@ serializationTestObject(const ParallelWellInfo<Scalar>& pinfo)
} }
template<class Scalar> 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() ); wtest_state->filter_wells( this->well_state.wells() );
this->well_test_state = std::move(wtest_state); this->well_test_state = std::move(*wtest_state);
} }
template<class Scalar> template<class Scalar>

View File

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