Skip to content
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

[3.12] gh-122527: Fix a crash on deallocation of PyStructSequence (GH-122577) #122626

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Aug 2, 2024

The PyStructSequence destructor would crash if it was deallocated after its type's dictionary was cleared by the GC, because it couldn't compute the "real size" of the instance. This could occur with relatively straightforward code in the free-threaded build or with a reference cycle involving the type in the default build, due to differing orders in which tp_clear() was called.

Account for the non-sequence fields in tp_basicsize and use that, along with Py_SIZE(), to compute the "real" size of a PyStructSequence in the dealloc function. This avoids the accesses to the type's dictionary during dealloc, which were unsafe. (cherry picked from commit 4b63cd1)

…nce` (pythonGH-122577)

The `PyStructSequence` destructor would crash if it was deallocated after
its type's dictionary was cleared by the GC, because it couldn't compute
the "real size" of the instance. This could occur with relatively
straightforward code in the free-threaded build or with a reference
cycle involving the type in the default build, due to differing orders
in which `tp_clear()` was called.

Account for the non-sequence fields in `tp_basicsize` and use that,
along with `Py_SIZE()`, to compute the "real" size of a
`PyStructSequence` in the dealloc function. This avoids the accesses to
the type's dictionary during dealloc, which were unsafe.
(cherry picked from commit 4b63cd1)

Co-authored-by: Sam Gross <[email protected]>
@ambv ambv merged commit 1bfb58c into python:3.12 Sep 6, 2024
31 checks passed
@colesbury colesbury deleted the backport-4b63cd1-3.12 branch December 4, 2024 20:23
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.

3 participants