diff --git a/Lib/test/test_tuple.py b/Lib/test/test_tuple.py index c37adc25458..53065bb2046 100644 --- a/Lib/test/test_tuple.py +++ b/Lib/test/test_tuple.py @@ -146,6 +146,9 @@ class TupleTest(seq_tests.CommonTest): 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) diff --git a/Misc/NEWS b/Misc/NEWS index 850369e1579..d3b26a4e0f7 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1? 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. diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 290107ad346..884174dca4e 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -850,7 +850,8 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) /* 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++) {