Skip to content

Fixed segfault in ClassDerived.tp_dealloc #1330

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

Merged
merged 4 commits into from
Dec 18, 2020
Merged

Conversation

lostmsu
Copy link
Member

@lostmsu lostmsu commented Dec 17, 2020

What caused the problem + fixes

  1. All reflected .NET types stored GCHandle pointing to their implementations past the last byte of PyTypeObject. By adding IntPtr.Size to the size of PyTypeObject for CLR metatype we ensure, that the necessary space is allocated without relying on Python never writing immediately after type instances.

  2. In ClassDerivedObject tp_dealloc tried to use tpHandle which was previously NULLed in tp_clear. Fortunately, tpHandle in ClassDerivedObject is merely a duplicate of PyObject_TYPE(pyHandle), so could be read from there.

Does this close any currently open issues?

#1327

Because tp_clear sets tpHandle to NULL, it can't be used.
Fortunately, we can simply read object's type from pyHandle.
@lostmsu lostmsu changed the title WIP on bug #1327 Fixed segfault in ClassDerived.tp_dealloc Dec 18, 2020
@lostmsu lostmsu marked this pull request as ready for review December 18, 2020 07:05
@lostmsu lostmsu requested a review from filmor December 18, 2020 07:05
@filmor filmor merged commit 7e73b0d into pythonnet:master Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants