From 1179ff4b71e60b8ddf857e0b861d3e093c9605c5 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 15 Jul 2022 08:11:02 +0000 Subject: [PATCH 1/4] fix refleak --- Modules/_io/textio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 660396b8b03ead..e4b1310b8a182c 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1247,6 +1247,7 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, if (errors == Py_None) { errors = self->errors; } + Py_INCREF(encoding); } else { if (_PyUnicode_EqualToASCIIString(encoding, "locale")) { @@ -1262,6 +1263,7 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, const char *c_errors = PyUnicode_AsUTF8(errors); if (c_errors == NULL) { + Py_DECREF(encoding); return -1; } @@ -1269,16 +1271,17 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, PyObject *codec_info = _PyCodec_LookupTextEncoding( PyUnicode_AsUTF8(encoding), "codecs.open()"); if (codec_info == NULL) { + Py_DECREF(encoding); return -1; } if (_textiowrapper_set_decoder(self, codec_info, c_errors) != 0 || _textiowrapper_set_encoder(self, codec_info, c_errors) != 0) { Py_DECREF(codec_info); + Py_DECREF(encoding); return -1; } Py_DECREF(codec_info); - Py_INCREF(encoding); Py_INCREF(errors); Py_SETREF(self->encoding, encoding); Py_SETREF(self->errors, errors); From a63196cc80ec53d5fa90557eec6da054a6d0790e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 08:13:53 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-07-15-08-13-51.gh-issue-94857.9_KvZJ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-07-15-08-13-51.gh-issue-94857.9_KvZJ.rst diff --git a/Misc/NEWS.d/next/Library/2022-07-15-08-13-51.gh-issue-94857.9_KvZJ.rst b/Misc/NEWS.d/next/Library/2022-07-15-08-13-51.gh-issue-94857.9_KvZJ.rst new file mode 100644 index 00000000000000..e684415595d1d2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-07-15-08-13-51.gh-issue-94857.9_KvZJ.rst @@ -0,0 +1 @@ +Fix refleak in ``_io.TextIOWrapper.reconfigure``. Patch by Kumar Aditya. From dcfae4c235676b376d68b0f4080fb36c161670c0 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 15 Jul 2022 08:25:07 +0000 Subject: [PATCH 3/4] add missing incref --- Modules/_io/textio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index e4b1310b8a182c..cf71bf337765f5 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1256,6 +1256,7 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, return -1; } } + Py_INCREF(encoding); if (errors == Py_None) { errors = &_Py_ID(strict); } From fed6decd085bef1c95beb5d61e2c2c9c5299d8dc Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 15 Jul 2022 08:26:54 +0000 Subject: [PATCH 4/4] incref on else --- Modules/_io/textio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index cf71bf337765f5..89094d66f38343 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1255,8 +1255,9 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, if (encoding == NULL) { return -1; } + } else { + Py_INCREF(encoding); } - Py_INCREF(encoding); if (errors == Py_None) { errors = &_Py_ID(strict); }