From 5fd90634ed36887099f2bf85cdf2ee41502ce219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Fri, 9 Jan 2026 11:35:11 +0100 Subject: [PATCH] Fix dangling reference in InjectionTargetCalculator Store injection_phase by value instead of by reference to prevent dangling reference when the calculator is returned from a function. The previous code stored a const reference to the Phase parameter, which works when the calculator is constructed and used within the same scope (e.g., in GroupStateHelper::checkGroupConstraintsInj). However, when the calculator is returned from a e.g a function the temporary Phase value passed to the constructor is destroyed, leaving a dangling reference that can cause undefined behavior. --- opm/simulators/wells/TargetCalculator.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/simulators/wells/TargetCalculator.hpp b/opm/simulators/wells/TargetCalculator.hpp index c3432ab105..cde8c1d70f 100644 --- a/opm/simulators/wells/TargetCalculator.hpp +++ b/opm/simulators/wells/TargetCalculator.hpp @@ -98,7 +98,7 @@ private: const GroupStateHelperType& groupStateHelper_; const std::vector& resv_coeff_; const Group& group_; - const Phase& injection_phase_; + const Phase injection_phase_; Group::InjectionCMode cmode_; int pos_; GuideRateModel::Target target_;