changeset: 93478:ec1948191461 branch: 3.4 parent: 93473:33908f14c0eb user: Benjamin Peterson date: Wed Nov 12 10:19:46 2014 -0500 files: Lib/test/test_io.py Misc/NEWS Modules/_io/textio.c description: fix possible double free in TextIOWrapper.__init__ (closes #22849) diff -r 33908f14c0eb -r ec1948191461 Lib/test/test_io.py --- a/Lib/test/test_io.py Tue Nov 11 11:01:09 2014 -0500 +++ b/Lib/test/test_io.py Wed Nov 12 10:19:46 2014 -0500 @@ -2784,6 +2784,21 @@ self.assertFalse(err) self.assertEqual("ok", out.decode().strip()) + def test_issue22849(self): + class F(object): + def readable(self): return True + def writable(self): return True + def seekable(self): return True + + for i in range(10): + try: + self.TextIOWrapper(F(), encoding='utf-8') + except Exception: + pass + + F.tell = lambda x: 0 + t = self.TextIOWrapper(F(), encoding='utf-8') + class CTextIOWrapperTest(TextIOWrapperTest): io = io diff -r 33908f14c0eb -r ec1948191461 Misc/NEWS --- a/Misc/NEWS Tue Nov 11 11:01:09 2014 -0500 +++ b/Misc/NEWS Wed Nov 12 10:19:46 2014 -0500 @@ -36,6 +36,8 @@ Library ------- +- Issue #22849: Fix possible double free in the io.TextIOWrapper constructor. + - Issue #12728: Different Unicode characters having the same uppercase but different lowercase are now matched in case-insensitive regular expressions. diff -r 33908f14c0eb -r ec1948191461 Modules/_io/textio.c --- a/Modules/_io/textio.c Tue Nov 11 11:01:09 2014 -0500 +++ b/Modules/_io/textio.c Wed Nov 12 10:19:46 2014 -0500 @@ -1061,7 +1061,7 @@ } /* Finished sorting out the codec details */ - Py_DECREF(codec_info); + Py_CLEAR(codec_info); self->buffer = buffer; Py_INCREF(buffer);