diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-05-26 05:38:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 05:38:51 -0700 |
commit | 7df9c41c69e2af8d0d36452c09d243b0975495af (patch) | |
tree | 9003b56f2ba701b984190bbe247fba7a0c24bd61 /Modules/_sqlite/module.c | |
parent | 66391b0c6e792236b9f487283ae161bdaf0e7ad7 (diff) | |
download | cpython-git-7df9c41c69e2af8d0d36452c09d243b0975495af.tar.gz |
bpo-40737: Fix possible reference leak for sqlite3 initialization (GH-20323)
(cherry picked from commit 5eb45d7d4e812e89d77da84cc619e9db81561a34)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Diffstat (limited to 'Modules/_sqlite/module.c')
-rw-r--r-- | Modules/_sqlite/module.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 4d9d3d41c7..71d951ee88 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; |