Skip to content

[3.12] gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-109539) #109545

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 2 commits into from
Sep 18, 2023

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Sep 18, 2023

On a Python built in debug mode, Py_DECREF() now calls
_Py_NegativeRefcount() if the object is a dangling pointer to
deallocated memory: memory filled with 0xDD "dead byte" by the debug
hook on memory allocators. The fix is to check the reference count
before checking for _Py_IsImmortal().

Add test_decref_freed_object() to test_capi.test_misc.
(cherry picked from commit 0bb0d88)

Co-authored-by: Victor Stinner [email protected]

…onGH-109539)

On a Python built in debug mode, Py_DECREF() now calls
_Py_NegativeRefcount() if the object is a dangling pointer to
deallocated memory: memory filled with 0xDD "dead byte" by the debug
hook on memory allocators. The fix is to check the reference count
*before* checking for _Py_IsImmortal().

Add test_decref_freed_object() to test_capi.test_misc.
(cherry picked from commit 0bb0d88)

Co-authored-by: Victor Stinner <[email protected]>
@Yhg1s Yhg1s enabled auto-merge (squash) September 18, 2023 16:09
@Yhg1s Yhg1s disabled auto-merge September 18, 2023 17:11
@Yhg1s Yhg1s enabled auto-merge (squash) September 18, 2023 17:12
@Yhg1s Yhg1s merged commit 74a7f5d into python:3.12 Sep 18, 2023
@miss-islington miss-islington deleted the backport-0bb0d88-3.12 branch September 18, 2023 17:39
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