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