8000 bpo-40737: Fix possible reference leak for sqlite3 initialization (GH… · python/cpython@5eb45d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5eb45d7

Browse files
author
Erlend Egeberg Aasland
authored
bpo-40737: Fix possible reference leak for sqlite3 initialization (GH-20323)
1 parent be63019 commit 5eb45d7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix possible reference leak for :mod:`sqlite3` initialization.

Modules/_sqlite/module.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ static struct PyModuleDef _sqlite3module = {
346346
NULL
347347
};
348348

349+
#define ADD_TYPE(module, type) \
350+
do { \
351+
if (PyModule_AddType(module, &type) < 0) { \
352+
Py_DECREF(module); \
353+
return NULL; \
354+
} \
355+
} while (0)
356+
349357
PyMODINIT_FUNC PyInit__sqlite3(void)
350358
{
351359
PyObject *module, *dict;
@@ -366,14 +374,10 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
366374
return NULL;
367375
}
368376

369-
Py_INCREF(&pysqlite_ConnectionType);
370-
PyModule_AddObject(module, "Connection", (PyObject*) &pysqlite_ConnectionType);
371-
Py_INCREF(&pysqlite_CursorType);
372-
PyModule_AddObject(module, "Cursor", (PyObject*) &pysqlite_CursorType);
373-
Py_INCREF(&pysqlite_PrepareProtocolType);
374-
PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pysqlite_PrepareProtocolType);
375-
Py_INCREF(&pysqlite_RowType);
376-
PyModule_AddObject(module, "Row", (PyObject*) &pysqlite_RowType);
377+
ADD_TYPE(module, pysqlite_ConnectionType);
378+
ADD_TYPE(module, pysqlite_CursorType);
379+
ADD_TYPE(module, pysqlite_PrepareProtocolType);
380+
ADD_TYPE(module, pysqlite_RowType);
377381

378382
if (!(dict = PyModule_GetDict(module))) {
379383
goto error;

0 commit comments

Comments
 (0)
2A6C
0