https://github.com/python/cpython/commit/4df47d8e60020f8961cab2be1ea7267bf16fd128
commit: 4df47d8e60020f8961cab2be1ea7267bf16fd128
branch: main
author: Jelle Zijlstra <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-22T21:50:43Z
summary:
gh-159739: Keep SQLite list parameters alive while binding (#160192)
When a SQL parameter sequence is an exact list, sqlite3 retrieved an element as
a borrowed reference before taking ownership. On free-threaded builds another
thread can replace it in between, so binding can use a freed object and crash.
Fetch a strong reference atomically. Backport to 3.15 and 3.14.
files:
A Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst
M Modules/_sqlite/cursor.c
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 000000000000000..fa000802ef713bf
--- /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 5c0ed26a3aabbe8..f1a3087a91f981d 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -701,8 +701,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);
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]