summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2020-05-26 12:18:19 (GMT)
committerGitHub <noreply@github.com>2020-05-26 12:18:19 (GMT)
commit5eb45d7d4e812e89d77da84cc619e9db81561a34 (patch)
tree84523d3422a9c7e23dfe5059d1e4cb54cb2c6085 /Modules
parentbe63019ed726b2da045bf232782062830bb6c27d (diff)
downloadcpython-5eb45d7d4e812e89d77da84cc619e9db81561a34.zip
cpython-5eb45d7d4e812e89d77da84cc619e9db81561a34.tar.gz
cpython-5eb45d7d4e812e89d77da84cc619e9db81561a34.tar.bz2
bpo-40737: Fix possible reference leak for sqlite3 initialization (GH-20323)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sqlite/module.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 4d9d3d4..71d951e 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -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;