]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44304: Ensure the sqlite3 destructor callback is always called with the GIL held...
authorPablo Galindo <Pablogsal@gmail.com>
Sat, 5 Jun 2021 22:41:11 +0000 (23:41 +0100)
committerGitHub <noreply@github.com>
Sat, 5 Jun 2021 22:41:11 +0000 (23:41 +0100)
Modules/_sqlite/connection.c
Modules/_sqlite/statement.c

index c2f3bc0f2012509d086ce73a50cd3c80641078c6..fbee1b7ce52a24724b35e1bd4bf685647125c8c6 100644 (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]
index c9dd8829453286bec5a7e6084f968b3a4ceeed57..f12ef67d261c742d6f8080981517222b3d676530 100644 (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);