summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-07-12 19:58:39 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-07-12 19:58:39 (GMT)
commit093c8e4bf053dfe5a9b46945cca2113e80809dfc (patch)
tree10b0b6f5406dc6f603a74444191d5b4504ebb57b /Lib/test/test_io.py
parent126edb56074371c1751f19770854b2fdf3dd4706 (diff)
parent84f1b1718da7fcbb8b8d255c166ef1ec0e03cd21 (diff)
downloadcpython-093c8e4bf053dfe5a9b46945cca2113e80809dfc.zip
cpython-093c8e4bf053dfe5a9b46945cca2113e80809dfc.tar.gz
cpython-093c8e4bf053dfe5a9b46945cca2113e80809dfc.tar.bz2
Issue #12149: Update the method cache after a type's dictionnary gets
cleared by the garbage collector. This fixes a segfault when an instance and its type get caught in a reference cycle, and the instance's deallocator calls one of the methods on the type (e.g. when subclassing IOBase). Diagnosis and patch by Davide Rizzo.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 0ffb4a1..419921f 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -611,7 +611,24 @@ class IOTest(unittest.TestCase):
self.assertEqual(rawio.read(2), b"")
class CIOTest(IOTest):
- pass
+
+ def test_IOBase_finalize(self):
+ # Issue #12149: segmentation fault on _PyIOBase_finalize when both a
+ # class which inherits IOBase and an object of this class are caught
+ # in a reference cycle and close() is already in the method cache.
+ class MyIO(self.IOBase):
+ def close(self):
+ pass
+
+ # create an instance to populate the method cache
+ MyIO()
+ obj = MyIO()
+ obj.obj = obj
+ wr = weakref.ref(obj)
+ del MyIO
+ del obj
+ support.gc_collect()
+ self.assertTrue(wr() is None, wr)
class PyIOTest(IOTest):
pass