summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-10-05 17:55:56 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-10-05 17:55:56 (GMT)
commitb619bb27edba24c9c1ca08b682e08afd33e9ea0f (patch)
tree658c477f2d04e11d99fd7a9b67ac6f2b61f3dc88 /Lib
parentbb10a1f7597e3976eda0797b23f5aece3b2ff248 (diff)
parent42c28cdd1dbebbf241c1828ffceabf7978ddf566 (diff)
downloadcpython-b619bb27edba24c9c1ca08b682e08afd33e9ea0f.zip
cpython-b619bb27edba24c9c1ca08b682e08afd33e9ea0f.tar.gz
cpython-b619bb27edba24c9c1ca08b682e08afd33e9ea0f.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')
-rw-r--r--Lib/test/test_io.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 455eda3..a9e3c37 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2421,6 +2421,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