Same class of bug as gh-146452 but in the list pickling path. batch_list_exact() uses PyList_GET_ITEM() which returns a borrowed reference, and a concurrent list.clear() or mutation can free the backing array before Py_INCREF gets to it.
Found while working on the dict fix in gh-146452 — checked the list path and it has the same pattern.
batch_list_exact() iterates list items using PyList_GET_ITEM() (borrowed ref) at lines 3196 and 3212. A concurrent list mutation can invalidate the borrowed reference before Py_INCREF. Same pattern as the dict issue in gh-146452.
Possible fix
Same helper function approach as gh-146452 — wrap batch_list_exact in Py_BEGIN_CRITICAL_SECTION(obj) / Py_END_CRITICAL_SECTION(). Happy to send a PR.
Activity
picnixz commented on Mar 27, 2026
I'm going to close this as a duplicate of #146452. Please update the title of your PR and the NEWS entry as well. TiA.