From 226a012d1cd61f42ecd3056c554922f359a1a35d Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Fri, 4 Dec 2020 19:45:57 -0800 Subject: bpo-42536: GC track recycled tuples (GH-23623) Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector: - collections.OrderedDict.items - dict.items - enumerate - functools.reduce - itertools.combinations - itertools.combinations_with_replacement - itertools.permutations - itertools.product - itertools.zip_longest - zip Previously, they could have become untracked by a prior garbage collection. --- Python/bltinmodule.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index a73b8cb320..352fb83d55 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2636,6 +2636,11 @@ zip_next(zipobject *lz) PyTuple_SET_ITEM(result, i, item); Py_DECREF(olditem); } + // bpo-42536: The GC may have untracked this result tuple. Since we're + // recycling it, make sure it's tracked again: + if (!_PyObject_GC_IS_TRACKED(result)) { + _PyObject_GC_TRACK(result); + } } else { result = PyTuple_New(tuplesize); if (result == NULL) -- cgit v1.2.1