diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-12 20:04:20 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-12 20:04:20 (GMT) |
commit | 1616645a0032b45c935ec6bdbb1d46b3febf0827 (patch) | |
tree | 402f294b56e32dbc6066a176d5f609a18bc125dc /Lib/test/test_io.py | |
parent | 0504532c39ffdf6cb8e4b7b283da60027473a4a5 (diff) | |
download | cpython-1616645a0032b45c935ec6bdbb1d46b3febf0827.zip cpython-1616645a0032b45c935ec6bdbb1d46b3febf0827.tar.gz cpython-1616645a0032b45c935ec6bdbb1d46b3febf0827.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.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 0bc5800..c423dd6 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -585,7 +585,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): test_array_writes = unittest.skip( |