[Python-checkins] r76763 - in python/trunk: Lib/test/test_tuple.py Objects/tupleobject.c

antoine.pitrou python-checkins at python.org
Sat Dec 12 20:13:08 CET 2009


Author: antoine.pitrou
Date: Sat Dec 12 20:13:08 2009
New Revision: 76763

Log:
Issue #7466: segmentation fault when the garbage collector is called
in the middle of populating a tuple.  Patch by Florent Xicluna.

(note: no NEWS entry for trunk since the bug was introduced in 2.7/3.1)




Modified:
   python/trunk/Lib/test/test_tuple.py
   python/trunk/Objects/tupleobject.c

Modified: python/trunk/Lib/test/test_tuple.py
==============================================================================
--- python/trunk/Lib/test/test_tuple.py	(original)
+++ python/trunk/Lib/test/test_tuple.py	Sat Dec 12 20:13:08 2009
@@ -146,6 +146,9 @@
             pass
         self.check_track_dynamic(MyTuple, True)
 
+    def test_bug7466(self):
+        # Trying to untrack an unfinished tuple could crash Python
+        self._not_tracked(tuple(gc.collect() for i in range(101)))
 
 def test_main():
     test_support.run_unittest(TupleTest)

Modified: python/trunk/Objects/tupleobject.c
==============================================================================
--- python/trunk/Objects/tupleobject.c	(original)
+++ python/trunk/Objects/tupleobject.c	Sat Dec 12 20:13:08 2009
@@ -875,7 +875,8 @@
 
 	/* XXX UNREF/NEWREF interface should be more symmetrical */
 	_Py_DEC_REFTOTAL;
-	_PyObject_GC_UNTRACK(v);
+	if (_PyObject_GC_IS_TRACKED(v))
+		_PyObject_GC_UNTRACK(v);
 	_Py_ForgetReference((PyObject *) v);
 	/* DECREF items deleted by shrinkage */
 	for (i = newsize; i < oldsize; i++) {


More information about the Python-checkins mailing list