Skip to content

Check for ref counting bugs in debug mode caused by immortal objects. #94851

Closed
@kumaraditya303

Description

@kumaraditya303

With #90699, the identifiers are statically allocated and are immortal. This makes it easy to make reference counting mistakes as they are not detected and cause negative ref count in _Py_RefTotal.

On my machine the reference count is negative because of missing incref on &_Py_STR(empty):

@kumaraditya303 ➜ /workspaces/cpython (main) $ ./python -I -X showrefcount -c pass
[-1 refs, 0 blocks]

PR #94850 fixes this issue.


To make it easy to discover reference counting issue, I propose to after each runtime finalization check that all the static allocated immortal objects have ref count of 999999999 otherwise _PyObject_Dump can be used to output the object and abort the process in debug mode and this will help prevent these kinds of issues of "unstable" ref count.

cc @ericsnowcurrently

Linked PRs

Metadata

Metadata

Labels

3.12only security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions