Skip to content

faulthandler_get_fileno returns borrowed sys.stderr without incref, leading to unintended decref #142442

@AZero13

Description

@AZero13

Bug report

Bug description:

faulthandler_get_fileno fetches sys.stderr with PySys_GetAttr (borrowed ref) when file is NULL/Py_None, then hands it back to callers who Py_XDECREF it. Because we never incref the borrowed ref, we end up decref-ing sys.stderr (or Py_None on the error path), potentially dropping its refcount unexpectedly.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions