diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-06-04 20:09:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 20:09:40 -0700 |
commit | ad2f3b74b5615aa36a82d1fdbc45bb7468aa1d72 (patch) | |
tree | 9e462a2a700aeb224284a8cdde5f1a3fff78bfff /Modules/_sqlite/statement.c | |
parent | 4642caf232a3f01468e76f19cd0c88175e10ee28 (diff) | |
download | cpython-git-ad2f3b74b5615aa36a82d1fdbc45bb7468aa1d72.tar.gz |
bpo-44304: Fix crash in the sqlite3 module when the GC clears Statement objects (GH-26545)
(cherry picked from commit fa106a685c1f199aca5be5c2d0277a14cc9057bd)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r-- | Modules/_sqlite/statement.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index e6dc4fd895..cf7fba6ce9 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -397,6 +397,10 @@ stmt_dealloc(pysqlite_Statement *self) if (self->in_weakreflist != NULL) { PyObject_ClearWeakRefs((PyObject*)self); } + if (self->st) { + sqlite3_finalize(self->st); + self->st = 0; + } tp->tp_clear((PyObject *)self); tp->tp_free(self); Py_DECREF(tp); @@ -405,13 +409,6 @@ stmt_dealloc(pysqlite_Statement *self) static int stmt_clear(pysqlite_Statement *self) { - if (self->st) { - Py_BEGIN_ALLOW_THREADS - sqlite3_finalize(self->st); - Py_END_ALLOW_THREADS - self->st = 0; - } - Py_CLEAR(self->sql); return 0; } |