Skip to content

GH-127705: better double free message. - #130785

Merged
markshannon merged 3 commits into
python:mainfrom
faster-cpython:better-double-free-message
Mar 5, 2025
Merged

markshannon merged 3 commits into
python:mainfrom
faster-cpython:better-double-free-message

Conversation

@markshannon

@markshannon markshannon commented Mar 3, 2025 •

Copy link
Copy Markdown
Member

Adds a Py_STACKREF_CLOSE_DEBUG #definable option to track closed stack refs. This gives us precise locations for the the initial close and subsequent use or close.

For example, there is a use-after-free in BINARY_OP_INPLACE_ADD_UNICODE (which this PR does not fix)

On main the error message is this:

Fatal Python error: _Py_stackref_record_borrow:
   Invalid StackRef with ID 15618638

With this PR it looks like this:

 Fatal Python error: _Py_stackref_record_borrow: 
   Borrow of closed ref ID 15609203 at Python/generated_cases.c.h:59.
   Referred to instance of str at 0x55a2b6c5ff10. 
   Closed at Python/generated_cases.c.h:344

(I've reformatted the messages for clarity, but the content is unchanged):

@markshannon
markshannon merged commit 78d50e9 into python:main Mar 5, 2025
@markshannon
markshannon deleted the better-double-free-message branch March 5, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants