bpo-42021: Fix possible ref leaks during _sqlite3 module init (GH-22673)

This commit is contained in:
Erlend Egeberg Aasland 2020-10-15 14:20:15 +02:00 committed by GitHub
parent b67cbbda3a
commit 644e94272a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 130 deletions

View file

@ -37,14 +37,19 @@ static PyObject *psyco_adapters = NULL;
/* pysqlite_microprotocols_init - initialize the adapters dictionary */
int
pysqlite_microprotocols_init(PyObject *dict)
pysqlite_microprotocols_init(PyObject *module)
{
/* create adapters dictionary and put it in module namespace */
if ((psyco_adapters = PyDict_New()) == NULL) {
return -1;
}
return PyDict_SetItemString(dict, "adapters", psyco_adapters);
if (PyModule_AddObject(module, "adapters", psyco_adapters) < 0) {
Py_DECREF(psyco_adapters);
return -1;
}
return 0;
}