GH-90699: fix ref counting of static immortal strings (gh-94850)

This commit is contained in:
Kumar Aditya 2022-07-20 11:53:30 +05:30 committed by GitHub
parent 88e4eeba25
commit 1834133e66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View file

@ -0,0 +1 @@
Fix reference counting bug in :meth:`bool.__repr__`. Patch by Kumar Aditya.

View file

@ -2244,7 +2244,7 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
Py_CLEAR(chunks); Py_CLEAR(chunks);
} }
if (line == NULL) { if (line == NULL) {
line = &_Py_STR(empty); line = Py_NewRef(&_Py_STR(empty));
} }
return line; return line;

View file

@ -9,7 +9,8 @@
static PyObject * static PyObject *
bool_repr(PyObject *self) 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 */ /* Function to return a bool from a C long */