Skip to content

fix possibly leaked borow in PyRef::into_super#5253

Closed
Icxolu wants to merge 1 commit intoPyO3:mainfrom
Icxolu:pyref-intosuper
Closed

fix possibly leaked borow in PyRef::into_super#5253
Icxolu wants to merge 1 commit intoPyO3:mainfrom
Icxolu:pyref-intosuper

Conversation

@Icxolu
Copy link
Member

@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 🙃

/// ```
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
Member 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... 😞

Copy link
Member

Choose a reason for hiding this comment

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

I think I've had an insight here - see #5281

@Icxolu
Copy link
Member Author

Icxolu commented Aug 2, 2025

Superseeded by #5281

@Icxolu Icxolu closed this Aug 2, 2025
@Icxolu Icxolu deleted the pyref-intosuper branch August 4, 2025 21:09
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