Skip to content

Commit 6345ae9

Browse files
committed
gh-142442: Increase the borrowed ref from faulthandler_get_fileno when file is not None instead of decreasing when it is none
Increase the borrowed ref from faulthandler_get_fileno when file is not None instead of decreasing when it is none
1 parent 726e8e8 commit 6345ae9

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix faulthandler’s fallback to `sys.stderr` so it owns the reference it
2+
returns, preventing an accidental decref of `sys.stderr` (or `None`) when no
3+
file is provided.

Modules/faulthandler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ faulthandler_get_fileno(PyObject **file_ptr)
112112
}
113113
if (file == Py_None) {
114114
PyErr_SetString(PyExc_RuntimeError, "sys.stderr is None");
115-
Py_DECREF(file);
116115
return -1;
117116
}
117+
Py_INCREF(file);
118118
}
119119
else if (PyLong_Check(file)) {
120120
if (PyBool_Check(file)) {

0 commit comments

Comments
 (0)