[Python-checkins] bpo-45581: Raise `MemoryError` in `sqlite3.connect` if SQLite signals memory error (GH-29171)

ambv webhook-mailer at python.org
Fri Oct 29 16:22:07 EDT 2021


https://github.com/python/cpython/commit/e2e62b3808691e15fa44b883270023e42dcad958
commit: e2e62b3808691e15fa44b883270023e42dcad958
branch: main
author: Erlend Egeberg Aasland <erlend.aasland at innova.no>
committer: ambv <lukasz at langa.pl>
date: 2021-10-29T22:21:58+02:00
summary:

bpo-45581: Raise `MemoryError` in `sqlite3.connect` if SQLite signals memory error (GH-29171)

files:
A Misc/NEWS.d/next/Library/2021-10-22-21-57-02.bpo-45581.rlH6ay.rst
M Modules/_sqlite/connection.c

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 0000000000000..13a3b237434eb
--- /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.
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index da2f12e8f99c2..94c38ad395440 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;



More information about the Python-checkins mailing list