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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
classderived: handle tp_dealloc called after tp_clear
Because tp_clear sets tpHandle to NULL, it can't be used.
Fortunately, we can simply read object's type from pyHandle.
  • Loading branch information
lostmsu committed Dec 18, 2020
commit 38b3f01ad70f5d622788f28dd45af572478f14d4
3 changes: 2 additions & 1 deletion src/runtime/classderived.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ internal ClassDerivedObject(Type tp) : base(tp)
// So we don't call PyObject_GC_Del here and instead we set the python
// reference to a weak reference so that the C# object can be collected.
GCHandle gc = GCHandle.Alloc(self, GCHandleType.Weak);
Marshal.WriteIntPtr(self.pyHandle, ObjectOffset.magic(self.tpHandle), (IntPtr)gc);
int gcOffset = ObjectOffset.magic(Runtime.PyObject_TYPE(self.pyHandle));
Marshal.WriteIntPtr(self.pyHandle, gcOffset, (IntPtr)gc);
self.gcHandle.Free();
self.gcHandle = gc;
}
Expand Down