Skip to content

fix possibly leaked borow in PyRef::into_super #5253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Jul 21, 2025

@Icxolu Icxolu added the bugfix label Jul 21, 2025
@Icxolu Icxolu force-pushed the pyref-intosuper branch from 237743a to cfcd5ea Compare July 21, 2025 21:23
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks - and uh oh I think I see another case 🙃

@@ -366,6 +366,15 @@ where
/// ```
pub fn into_super(self) -> PyRef<'p, U> {
let py = self.py();
if <U::Frozen as crate::pyclass::boolean_struct::private::Boolean>::VALUE {
Copy link
Member

Choose a reason for hiding this comment

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

Checking the constant value is a neat solution.

Crazy question though, what if U is itself a child of another type V which is not frozen?

Then I think the borrow flag is owned by V and it would be incorrect to release here 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right... And If we have something like

Base (frozen) -> S1(mut) -> S2(frozen) -> S3(mut)

The counter is owned by S1 I think, so S3 -> S2 should keep it, while S1 -> Base should release it 😭

I feel like this needs to be solved in the borrow checker itself and cant be worked around here... 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants