]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-90699: fix ref counting of static immortal strings (gh-94850)
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Wed, 20 Jul 2022 06:23:30 +0000 (11:53 +0530)
committerGitHub <noreply@github.com>
Wed, 20 Jul 2022 06:23:30 +0000 (15:23 +0900)
Misc/NEWS.d/next/Core and Builtins/2022-07-14-10-07-53.gh-issue-90699.x3aG9m.rst [new file with mode: 0644]
Modules/_io/textio.c
Objects/boolobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-07-14-10-07-53.gh-issue-90699.x3aG9m.rst b/Misc/NEWS.d/next/Core and Builtins/2022-07-14-10-07-53.gh-issue-90699.x3aG9m.rst
new file mode 100644 (file)
index 0000000..795f4df
--- /dev/null
@@ -0,0 +1 @@
+Fix reference counting bug in :meth:`bool.__repr__`. Patch by Kumar Aditya.
index 89094d66f383435b5417c0394ad98e1d414fad6c..3369694653fd9693818a3267bdda2129fe5b3d49 100644 (file)
@@ -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;
index ff7218760ab361f11c23fb272a16b3b680bb28f2..8a20e368d4a42bc65a69e7fb9a4e7bb06996e286 100644 (file)
@@ -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 */