summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorƁukasz Langa <lukasz@langa.pl>2021-10-29 23:02:19 +0200
committerGitHub <noreply@github.com>2021-10-29 23:02:19 +0200
commited807bf333cdc78b92c9861600acf1a435c52193 (patch)
treed7c1c10c555335c7af6e8a2dd369a7b106f5e5a0
parent3ec1124de289496efabc43a02cc88b3c59e1e238 (diff)
downloadcpython-git-ed807bf333cdc78b92c9861600acf1a435c52193.tar.gz
[3.9] bpo-45581: Raise `MemoryError` in `sqlite3.connect` if SQLite signals memory error (GH-29171) (GH-29324)
(cherry picked from commit e2e62b3808691e15fa44b883270023e42dcad958) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
-rw-r--r--Misc/NEWS.d/next/Library/2021-10-22-21-57-02.bpo-45581.rlH6ay.rst2
-rw-r--r--Modules/_sqlite/connection.c4
2 files changed, 6 insertions, 0 deletions
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 0000000000..13a3b23743
--- /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 68bf97389a..30e333a4b8 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -134,6 +134,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
Py_DECREF(database_obj);
+ if (self->db == NULL && rc == SQLITE_NOMEM) {
+ PyErr_NoMemory();
+ return -1;
+ }
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db, NULL);
return -1;