Skip to content

Commit cd04626

Browse files
[3.14] gh-159739: Keep SQLite list parameters alive while binding (GH-160192) (#160362)
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. (cherry picked from commit 4df47d8) Co-authored-by: Jelle Zijlstra <jelle@openai.com>
1 parent ef35d82 commit cd04626

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a possible crash when a list of :mod:`sqlite3` parameters is modified concurrently on a free-threaded build.

‎Modules/_sqlite/cursor.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,7 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
686686
PyObject *item = PyTuple_GET_ITEM(parameters, i);
687687
current_param = Py_NewRef(item);
688688
} else if (PyList_CheckExact(parameters)) {
689-
PyObject *item = PyList_GetItem(parameters, i);
690-
current_param = Py_XNewRef(item);
689+
current_param = PyList_GetItemRef(parameters, i);
691690
} else {
692691
current_param = PySequence_GetItem(parameters, i);
693692
}

0 commit comments

Comments
 (0)