Skip to content

Commit

Permalink
bpo-44304: Ensure the sqlite3 destructor callback is always called wi…
Browse files Browse the repository at this point in the history
…th the GIL held (pythonGH-26551)

(cherry picked from commit 6e3b7cf)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
  • Loading branch information
pablogsal authored and miss-islington committed Jun 5, 2021
1 parent ad2f3b7 commit 681328c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Modules/_sqlite/connection.c
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions Modules/_sqlite/statement.c
Expand Up @@ -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);
Expand Down

0 comments on commit 681328c

Please sign in to comment.