bpo-44304: Ensure the sqlite3 destructor callback is always called with the GIL held (GH-26551)

This commit is contained in:
Pablo Galindo 2021-06-05 23:41:11 +01:00 committed by GitHub
parent fa106a685c
commit 6e3b7cf3af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -825,7 +825,12 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
static void _destructor(void* args)
{
// This function may be called without the GIL held, so we need to ensure
// that we destroy 'args' with the GIL
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
Py_DECREF((PyObject*)args);
PyGILState_Release(gstate);
}
/*[clinic input]

View File

@ -404,7 +404,9 @@ stmt_dealloc(pysqlite_Statement *self)
PyObject_ClearWeakRefs((PyObject*)self);
}
if (self->st) {
Py_BEGIN_ALLOW_THREADS
sqlite3_finalize(self->st);
Py_END_ALLOW_THREADS
self->st = 0;
}
tp->tp_clear((PyObject *)self);