-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-15938: Hold onto the container after a get_property_ptr_ptr() call #20246
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
base: master
Are you sure you want to change the base?
Conversation
Effects performed after a get_property_ptr_ptr() call may make the property pointer invalid by freeing or reallocating its container. The container might be the object itself, the properties ht, a proxied object, or anything else (for internal classes). Here we change the get_property_ptr_ptr handler so it exposes the actual container. The caller can then increase its refcount if any operation performed before the last access to the property could render the property invalid. The get_property_ptr_ptr() implementation has the responsibility of ensuring that while the container's refcount is incremented, the property pointer remains valid.
iluuu1994
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach seems reasonable. It's a bit unfortunate that this API change is necessary only because of internal classes with fetch_ptr_ptr to custom storage that may also move, which should be very rare. FWIU, the properties table RC could simply always be increased along with the object RC, making that problem go away. For internal classes, maybe we could fix the issue in a different way by flagging the object for the duration of the ptr lifetime, and prevent changes being made to objects with such flags. This would require checks in multiple places, so might not be a better solution.
In any case, I don't object to this approach.
ndossche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach seems relatively simple and I can't immediately think of a problem. Will need to test more intensively coming week.
Effects performed after a get_property_ptr_ptr() call may make the property pointer invalid by freeing or reallocating its container.
The container might be the object itself, the properties ht, a proxied object. For internal classes, this can be anything else.
Here we change the get_property_ptr_ptr handler so it exposes the actual container. The caller can then increase its refcount if any operation performed before the last access to the property could render the property invalid.
The get_property_ptr_ptr() implementation has the responsibility of ensuring that while the container's refcount is incremented, the property pointer remains valid.
Fixes GH-15938
cc @iluuu1994 @nielsdos