Skip to content

Fix dangling reference in InjectionTargetCalculator#6719

Merged
hakonhagland merged 1 commit into
OPM:masterfrom
hakonhagland:phase_ref
Jan 9, 2026
Merged

Fix dangling reference in InjectionTargetCalculator#6719
hakonhagland merged 1 commit into
OPM:masterfrom
hakonhagland:phase_ref

Conversation

@hakonhagland
Copy link
Copy Markdown
Contributor

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.

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.
@hakonhagland hakonhagland added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Jan 9, 2026
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

Copy link
Copy Markdown
Member

@akva2 akva2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hakonhagland hakonhagland merged commit 356574b into OPM:master Jan 9, 2026
3 checks passed
@bska
Copy link
Copy Markdown
Member

bska commented Jan 9, 2026

For what it's worth, Opm::Phase is an enum and should therefore typically be stored/passed by value rather than reference.

@hakonhagland hakonhagland deleted the phase_ref branch March 16, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants