]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.12] gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-109539) (#109545)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 18 Sep 2023 17:39:27 +0000 (10:39 -0700)
committerGitHub <noreply@github.com>
Mon, 18 Sep 2023 17:39:27 +0000 (17:39 +0000)
commit74a7f5d2dacd4c05aad0e64a275dae97d18f5355
treed654c4b110caa5290f650689af46d6d6f8a8d59e
parent0620bc7f78782cd2e400827aaf834f358250778f
[3.12] gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-109539) (#109545)

gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-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 0bb0d88e2d4e300946e399e088e2ff60de2ccf8c)

Co-authored-by: Victor Stinner <vstinner@python.org>
Include/object.h
Lib/test/test_capi/test_misc.py
Misc/NEWS.d/next/Core and Builtins/2023-09-18-15-35-08.gh-issue-109496.Kleoz3.rst [new file with mode: 0644]
Modules/_testcapimodule.c