changeset 57666:d9785909c3a7

Merged revisions 76763 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r76763 | antoine.pitrou | 2009-12-12 20:13:08 +0100 (sam., 12 déc. 2009) | 7 lines 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) ........
author Antoine Pitrou <solipsis@pitrou.net>
date Sat, 12 Dec 2009 19:18:27 +0000
parents 7cb73e7c176d
children ad917b8fd64c
files Lib/test/test_tuple.py Misc/NEWS Objects/tupleobject.c
diffstat 3 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/test/test_tuple.py	Fri Dec 11 20:17:17 2009 +0000
+++ b/Lib/test/test_tuple.py	Sat Dec 12 19:18:27 2009 +0000
@@ -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():
     support.run_unittest(TupleTest)
--- a/Misc/NEWS	Fri Dec 11 20:17:17 2009 +0000
+++ b/Misc/NEWS	Sat Dec 12 19:18:27 2009 +0000
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #7466: segmentation fault when the garbage collector is called
+  in the middle of populating a tuple.  Patch by Florent Xicluna.
+
 - Issue #7419: setlocale() could crash the interpreter on Windows when called
   with invalid values.
 
--- a/Objects/tupleobject.c	Fri Dec 11 20:17:17 2009 +0000
+++ b/Objects/tupleobject.c	Sat Dec 12 19:18:27 2009 +0000
@@ -850,7 +850,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++) {