mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
						commit
						093c8e4bf0
					
				
					 4 changed files with 27 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -611,8 +611,25 @@ def test_RawIOBase_read(self):
 | 
			
		|||
        self.assertEqual(rawio.read(2), b"")
 | 
			
		||||
 | 
			
		||||
class CIOTest(IOTest):
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -785,6 +785,7 @@ Armin Rigo
 | 
			
		|||
Nicholas Riley
 | 
			
		||||
Jean-Claude Rimbault
 | 
			
		||||
Juan M. Bello Rivas
 | 
			
		||||
Davide Rizzo
 | 
			
		||||
Anthony Roach
 | 
			
		||||
Mark Roberts
 | 
			
		||||
Jim Robinson
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,12 @@ What's New in Python 3.3 Alpha 1?
 | 
			
		|||
Core and Builtins
 | 
			
		||||
-----------------
 | 
			
		||||
 | 
			
		||||
- 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.
 | 
			
		||||
 | 
			
		||||
- Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows.
 | 
			
		||||
 | 
			
		||||
- Issue #9642: Uniformize the tests on the availability of the mbcs codec, add
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -967,6 +967,8 @@ subtype_dealloc(PyObject *self)
 | 
			
		|||
    assert(basedealloc);
 | 
			
		||||
    basedealloc(self);
 | 
			
		||||
 | 
			
		||||
    PyType_Modified(type);
 | 
			
		||||
 | 
			
		||||
    /* Can't reference self beyond this point */
 | 
			
		||||
    Py_DECREF(type);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue