clear BufferedRWPair weakrefs on deallocation (closes #22517)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index af3b90a..2a3b4a3 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -1474,6 +1474,12 @@
pair = self.tp(SelectableIsAtty(True), SelectableIsAtty(True))
self.assertTrue(pair.isatty())
+ def test_weakref_clearing(self):
+ brw = self.tp(self.MockRawIO(), self.MockRawIO())
+ ref = weakref.ref(brw)
+ brw = None
+ ref = None # Shouldn't segfault.
+
class CBufferedRWPairTest(BufferedRWPairTest):
tp = io.BufferedRWPair