8000 GH-94857: fix test_io refleak (GH-94858) · python/cpython@631160c · GitHub
[go: up one dir, main page]

Skip to content

Commit 631160c

Browse files
GH-94857: fix test_io refleak (GH-94858)
1 parent ae0be5a commit 631160c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix refleak in ``_io.TextIOWrapper.reconfigure``. Patch by Kumar Aditya.

Modules/_io/textio.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,13 +1247,16 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
12471247
if (errors == Py_None) {
12481248
errors = self->errors;
12491249
}
1250+
Py_INCREF(encoding);
12501251
}
12511252
else {
12521253
if (_PyUnicode_EqualToASCIIString(encoding, "locale")) {
12531254
encoding = _Py_GetLocaleEncodingObject();
12541255
if (encoding == NULL) {
12551256
return -1;
12561257
}
1258+
} else {
1259+
Py_INCREF(encoding);
12571260
}
12581261
if (errors == Py_None) {
12591262
errors = &_Py_ID(strict);
@@ -1262,23 +1265,25 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
12621265

12631266
const char *c_errors = PyUnicode_AsUTF8(errors);
12641267
if (c_errors == NULL) {
1268+
Py_DECREF(encoding);
12651269
return -1;
12661270
}
12671271

12681272
// Create new encoder & decoder
12691273
PyObject *codec_info = _PyCodec_LookupTextEncoding(
12701274
PyUnicode_AsUTF8(encoding), "codecs.open()");
12711275
if (codec_info == NULL) {
1276+
Py_DECREF(encoding);
12721277
return -1;
12731278
}
12741279
if (_textiowrapper_set_decoder(self, codec_info, c_errors) != 0 ||
12751280
_textiowrapper_set_encoder(self, codec_info, c_errors) != 0) {
12761281
Py_DECREF(codec_info);
1282+
Py_DECREF(encoding);
12771283
return -1;
12781284
}
12791285
Py_DECREF(codec_info);
12801286

1281-
Py_INCREF(encoding);
12821287
Py_INCREF(errors);
12831288
Py_SETREF(self->encoding, encoding);
12841289
Py_SETREF(self->errors, errors);

0 commit comments

Comments
 (0)
0