Skip to content

Commit

Permalink
GH-90699: fix ref counting of static immortal strings (gh-94850)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 authored Jul 20, 2022
1 parent 88e4eeb commit 1834133
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix reference counting bug in :meth:`bool.__repr__`. Patch by Kumar Aditya.
2 changes: 1 addition & 1 deletion Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2244,7 +2244,7 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
Py_CLEAR(chunks);
}
if (line == NULL) {
line = &_Py_STR(empty);
line = Py_NewRef(&_Py_STR(empty));
}

return line;
Expand Down
3 changes: 2 additions & 1 deletion Objects/boolobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
static PyObject *
bool_repr(PyObject *self)
{
return self == Py_True ? &_Py_ID(True) : &_Py_ID(False);
PyObject *res = self == Py_True ? &_Py_ID(True) : &_Py_ID(False);
return Py_NewRef(res);
}

/* Function to return a bool from a C long */
Expand Down

0 comments on commit 1834133

Please sign in to comment.