Skip to content

Commit 317e9ed

Browse files
bpo-44304: Ensure the sqlite3 destructor callback is always called with the GIL held (GH-26551) (GH_26552)
(cherry picked from commit 6e3b7cf) Co-authored-by: Pablo Galindo <[email protected]>
1 parent ad2f3b7 commit 317e9ed

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Modules/_sqlite/connection.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,12 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
851851

852852
static void _destructor(void* args)
853853
{
854+
// This function may be called without the GIL held, so we need to ensure
855+
// that we destroy 'args' with the GIL
856+
PyGILState_STATE gstate;
857+
gstate = PyGILState_Ensure();
854858
Py_DECREF((PyObject*)args);
859+
PyGILState_Release(gstate);
855860
}
856861

857862
/*[clinic input]

Modules/_sqlite/statement.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ stmt_dealloc(pysqlite_Statement *self)
398398
PyObject_ClearWeakRefs((PyObject*)self);
399399
}
400400
if (self->st) {
401+
Py_BEGIN_ALLOW_THREADS
401402
sqlite3_finalize(self->st);
403+
Py_END_ALLOW_THREADS
402404
self->st = 0;
403405
}
404406
tp->tp_clear((PyObject *)self);

0 commit comments

Comments
 (0)