Builtin zip method is not safe under free-threading #123271
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
A common optimization technique (used in
zip_next
) for methods generating tuples is to keep an internal reference to the returned tuple and when the method is called again check whether the internal tuple has reference count 1. If the refcount is one, the tuple can be re-used. Under the free-threading build this is not safe: after the check on the reference count another thread can perform the same check and also re-use the tuple. This can lead to a double decref on the items of the tuple replaced and a double incref (memory leak) on the items of the tuple being set.Some options to address this:
A minimal example reproducing the issue is added as a test in #123272. It shows the issue when executed with a free-threading debug build.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: