diff options
author | Charles-François Natali <neologix@free.fr> | 2011-10-05 17:53:43 (GMT) |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2011-10-05 17:53:43 (GMT) |
commit | 42c28cdd1dbebbf241c1828ffceabf7978ddf566 (patch) | |
tree | f0a0e094b0039c4092dc30090a85b8993a6d74fe /Lib/test | |
parent | 1b7da519b09d8885272d323af982d36675419075 (diff) | |
download | cpython-42c28cdd1dbebbf241c1828ffceabf7978ddf566.zip cpython-42c28cdd1dbebbf241c1828ffceabf7978ddf566.tar.gz cpython-42c28cdd1dbebbf241c1828ffceabf7978ddf566.tar.bz2 |
Issue #13070: Fix a crash when a TextIOWrapper caught in a reference cycle
would be finalized after the reference to its underlying BufferedRWPair's
writer got cleared by the GC.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_io.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 53cabbb..eb2ac5f 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2414,6 +2414,21 @@ class CTextIOWrapperTest(TextIOWrapperTest): with self.open(support.TESTFN, "rb") as f: self.assertEqual(f.read(), b"456def") + def test_rwpair_cleared_before_textio(self): + # Issue 13070: TextIOWrapper's finalization would crash when called + # after the reference to the underlying BufferedRWPair's writer got + # cleared by the GC. + for i in range(1000): + b1 = self.BufferedRWPair(self.MockRawIO(), self.MockRawIO()) + t1 = self.TextIOWrapper(b1, encoding="ascii") + b2 = self.BufferedRWPair(self.MockRawIO(), self.MockRawIO()) + t2 = self.TextIOWrapper(b2, encoding="ascii") + # circular references + t1.buddy = t2 + t2.buddy = t1 + support.gc_collect() + + class PyTextIOWrapperTest(TextIOWrapperTest): pass |