Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c14f23

Browse files
committed
fix possible double free in TextIOWrapper.__init__ (closes #22849)
1 parent dfede95 commit 6c14f23

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/test/test_io.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,21 @@ def test_create_at_shutdown_with_encoding(self):
27842784
self.assertFalse(err)
27852785
self.assertEqual("ok", out.decode().strip())
27862786

2787+
def test_issue22849(self):
2788+
class F(object):
2789+
def readable(self): return True
2790+
def writable(self): return True
2791+
def seekable(self): return True
2792+
2793+
for i in range(10):
2794+
try:
2795+
self.TextIOWrapper(F(), encoding='utf-8')
2796+
except Exception:
2797+
pass
2798+
2799+
F.tell = lambda x: 0
2800+
t = self.TextIOWrapper(F(), encoding='utf-8')
2801+
27872802

27882803
class CTextIOWrapperTest(TextIOWrapperTest):
27892804
io = io

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #22849: Fix possible double free in the io.TextIOWrapper constructor.
40+
3941
- Issue #12728: Different Unicode characters having the same uppercase but
4042
different lowercase are now matched in case-insensitive regular expressions.
4143

Modules/_io/textio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
10611061
}
10621062

10631063
/* Finished sorting out the codec details */
1064-
Py_DECREF(codec_info);
1064+
Py_CLEAR(codec_info);
10651065

10661066
self->buffer = buffer;
10671067
Py_INCREF(buffer);

0 commit comments

Comments
 (0)