Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-108083: Don't ignore exceptions in sqlite3.Connection.__init__() a…
…nd .close()

Always check the return value of connection_exec_stmt()
  • Loading branch information
erlend-aasland committed Aug 17, 2023
commit 09567958c2cf031c3cd1614e04e1467c809d8cb0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix bugs in the constructor of :mod:`sqlite3.Connection` and
:meth:`sqlite3.Connection.close` where exceptions could be leaked. Patch by
Erlend E. Aasland.
8 changes: 6 additions & 2 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
self->initialized = 1;

if (autocommit == AUTOCOMMIT_DISABLED) {
(void)connection_exec_stmt(self, "BEGIN");
if (connection_exec_stmt(self, "BEGIN") < 0) {
return -1;
}
}
return 0;

Expand Down Expand Up @@ -449,7 +451,9 @@ connection_close(pysqlite_Connection *self)
if (_Py_IsInterpreterFinalizing(PyInterpreterState_Get())) {
remove_callbacks(self->db);
}
(void)connection_exec_stmt(self, "ROLLBACK");
if (connection_exec_stmt(self, "ROLLBACK") < 0) {
PyErr_WriteUnraisable(self);
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
}
}

free_callback_contexts(self);
Expand Down