]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40737: Fix possible reference leak for sqlite3 initialization (GH-20323)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Tue, 26 May 2020 12:18:19 +0000 (14:18 +0200)
committerGitHub <noreply@github.com>
Tue, 26 May 2020 12:18:19 +0000 (21:18 +0900)
Misc/NEWS.d/next/Library/2020-05-23-00-22-11.bpo-40737.iph-CM.rst [new file with mode: 0644]
Modules/_sqlite/module.c

diff --git a/Misc/NEWS.d/next/Library/2020-05-23-00-22-11.bpo-40737.iph-CM.rst b/Misc/NEWS.d/next/Library/2020-05-23-00-22-11.bpo-40737.iph-CM.rst
new file mode 100644 (file)
index 0000000..f068d3a
--- /dev/null
@@ -0,0 +1 @@
+Fix possible reference leak for :mod:`sqlite3` initialization.
index 4d9d3d41c7b71b9ab539bd3a8bf76d65455a9a0e..71d951ee887e47773a0e62f38650028062f21d2b 100644 (file)
@@ -346,6 +346,14 @@ static struct PyModuleDef _sqlite3module = {
         NULL
 };
 
+#define ADD_TYPE(module, type)                 \
+do {                                           \
+    if (PyModule_AddType(module, &type) < 0) { \
+        Py_DECREF(module);                     \
+        return NULL;                           \
+    }                                          \
+} while (0)
+
 PyMODINIT_FUNC PyInit__sqlite3(void)
 {
     PyObject *module, *dict;
@@ -366,14 +374,10 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
         return NULL;
     }
 
-    Py_INCREF(&pysqlite_ConnectionType);
-    PyModule_AddObject(module, "Connection", (PyObject*) &pysqlite_ConnectionType);
-    Py_INCREF(&pysqlite_CursorType);
-    PyModule_AddObject(module, "Cursor", (PyObject*) &pysqlite_CursorType);
-    Py_INCREF(&pysqlite_PrepareProtocolType);
-    PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pysqlite_PrepareProtocolType);
-    Py_INCREF(&pysqlite_RowType);
-    PyModule_AddObject(module, "Row", (PyObject*) &pysqlite_RowType);
+    ADD_TYPE(module, pysqlite_ConnectionType);
+    ADD_TYPE(module, pysqlite_CursorType);
+    ADD_TYPE(module, pysqlite_PrepareProtocolType);
+    ADD_TYPE(module, pysqlite_RowType);
 
     if (!(dict = PyModule_GetDict(module))) {
         goto error;