summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-07-18 14:17:55 (GMT)
committerGitHub <noreply@github.com>2022-07-18 14:17:55 (GMT)
commita914fa979e0d6043da4b591e02d2b99d26853411 (patch)
treeafdcd6581cea4aa39a965645867c912e585cc729 /Modules
parent4607e884e50227c3e7d784dd3a0b6809b4fb5fbf (diff)
downloadcpython-a914fa979e0d6043da4b591e02d2b99d26853411.zip
cpython-a914fa979e0d6043da4b591e02d2b99d26853411.tar.gz
cpython-a914fa979e0d6043da4b591e02d2b99d26853411.tar.bz2
GH-94857: fix test_io refleak (GH-94858)
(cherry picked from commit 631160c262b40bf4ce3da6cd7bbb972ae2e9fc91) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/textio.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 660396b..89094d6 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")) {
@@ -1254,6 +1255,8 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
if (encoding == NULL) {
return -1;
}
+ } else {
+ Py_INCREF(encoding);
}
if (errors == Py_None) {
errors = &_Py_ID(strict);
@@ -1262,6 +1265,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 +1273,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);