]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44304: Ensure the sqlite3 destructor callback is always called with the GIL held...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 5 Jun 2021 23:13:27 +0000 (16:13 -0700)
committerGitHub <noreply@github.com>
Sat, 5 Jun 2021 23:13:27 +0000 (00:13 +0100)
(cherry picked from commit 6e3b7cf3af3ed7758b2c2193c1d393feb8ab8f72)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Modules/_sqlite/connection.c
Modules/_sqlite/statement.c

index fccffabc4b2a0b20015c4c27c8328598c312a992..8e42a36bd3372983134e63aa4c1e984decb118fd 100644 (file)
@@ -851,7 +851,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 cf7fba6ce9a24cdd9b644197a597dc5f569c2408..072b07d4eaba5a9e4eb5f9c4bfb1b9c19f861724 100644 (file)
@@ -398,7 +398,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);