gh-139327: consolidate sqlite3_finalize and sqlite3_reset usages (GH-139329)

This commit is contained in:
Bénédikt Tran 2025-10-15 15:18:07 +02:00 committed by GitHub
parent 4126d9f1ab
commit 27acaf1cb7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 113 additions and 16 deletions

View file

@ -103,7 +103,12 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
return self;
error:
(void)sqlite3_finalize(stmt);
assert(PyErr_Occurred());
if (sqlite3_finalize(stmt) != SQLITE_OK) {
PyObject *exc = PyErr_GetRaisedException();
PyErr_SetString(connection->InternalError, "cannot finalize statement");
_PyErr_ChainExceptions1(exc);
}
return NULL;
}
@ -114,10 +119,16 @@ stmt_dealloc(PyObject *op)
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(op);
if (self->st) {
int rc;
Py_BEGIN_ALLOW_THREADS
sqlite3_finalize(self->st);
rc = sqlite3_finalize(self->st);
Py_END_ALLOW_THREADS
self->st = 0;
self->st = NULL;
if (rc != SQLITE_OK) {
pysqlite_state *state = PyType_GetModuleState(Py_TYPE(op));
PyErr_SetString(state->InternalError, "cannot finalize statement");
PyErr_FormatUnraisable("Exception ignored in stmt_dealloc()");
}
}
tp->tp_free(self);
Py_DECREF(tp);