From 49e5d8aaa5dd698697b0a6357fa65e6b9ba95922 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 22 Oct 2021 21:52:53 +0200 Subject: [PATCH 1/2] bpo-45581: raise MemoryError if sqlite3_open_v2() returns SQLITE_NOMEM --- Modules/_sqlite/connection.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index e94c4cbb4e8c3a..79773ae4225887 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -165,6 +165,10 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, (uri ? SQLITE_OPEN_URI : 0), NULL); Py_END_ALLOW_THREADS + if (self->db == NULL && rc == SQLITE_NOMEM) { + PyErr_NoMemory(); + return -1; + } if (rc != SQLITE_OK) { _pysqlite_seterror(state, self->db); return -1; From 0ffdb429daf98d4293bcfae17e3442e4791bb310 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 22 Oct 2021 21:57:07 +0200 Subject: [PATCH 2/2] Add NEWS --- .../next/Library/2021-10-22-21-57-02.bpo-45581.rlH6ay.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-10-22-21-57-02.bpo-45581.rlH6ay.rst diff --git a/Misc/NEWS.d/next/Library/2021-10-22-21-57-02.bpo-45581.rlH6ay.rst b/Misc/NEWS.d/next/Library/2021-10-22-21-57-02.bpo-45581.rlH6ay.rst new file mode 100644 index 00000000000000..13a3b237434eb9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-10-22-21-57-02.bpo-45581.rlH6ay.rst @@ -0,0 +1,2 @@ +:meth:`sqlite3.connect` now correctly raises :exc:`MemoryError` if the +underlying SQLite API signals memory error. Patch by Erlend E. Aasland.