Skip to content

Commit 6e3b7cf

Browse files
authored
bpo-44304: Ensure the sqlite3 destructor callback is always called with the GIL held (GH-26551)
1 parent fa106a6 commit 6e3b7cf

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
@@ -825,7 +825,12 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
825825

826826
static void _destructor(void* args)
827827
{
828+
// This function may be called without the GIL held, so we need to ensure
829+
// that we destroy 'args' with the GIL
830+
PyGILState_STATE gstate;
831+
gstate = PyGILState_Ensure();
828832
Py_DECREF((PyObject*)args);
833+
PyGILState_Release(gstate);
829834
}
830835

831836
/*[clinic input]

Modules/_sqlite/statement.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ stmt_dealloc(pysqlite_Statement *self)
404404
PyObject_ClearWeakRefs((PyObject*)self);
405405
}
406406
if (self->st) {
407+
Py_BEGIN_ALLOW_THREADS
407408
sqlite3_finalize(self->st);
409+
Py_END_ALLOW_THREADS
408410
self->st = 0;
409411
}
410412
tp->tp_clear((PyObject *)self);

0 commit comments

Comments
 (0)