diff --git a/Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst b/Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst new file mode 100644 index 00000000000000..fa000802ef713b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst @@ -0,0 +1 @@ +Fix a possible crash when a list of :mod:`sqlite3` parameters is modified concurrently on a free-threaded build. diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 4e6f46261b10bc..04b22f113b2b64 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -686,8 +686,7 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self, PyObject *item = PyTuple_GET_ITEM(parameters, i); current_param = Py_NewRef(item); } else if (PyList_CheckExact(parameters)) { - PyObject *item = PyList_GetItem(parameters, i); - current_param = Py_XNewRef(item); + current_param = PyList_GetItemRef(parameters, i); } else { current_param = PySequence_GetItem(parameters, i); }