]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-109496: Detect Py_DECREF() after dealloc in debug mode (#109539)
authorVictor Stinner <vstinner@python.org>
Mon, 18 Sep 2023 14:59:09 +0000 (16:59 +0200)
committerGitHub <noreply@github.com>
Mon, 18 Sep 2023 14:59:09 +0000 (14:59 +0000)
commit0bb0d88e2d4e300946e399e088e2ff60de2ccf8c
treee197a96bdf8c45937a2f839fd723a9bb58270c47
parentef659b96169888e52b6ff03ce28fffaaa8f76818
gh-109496: Detect Py_DECREF() after dealloc in debug mode (#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.
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