Skip to content
10 changes: 5 additions & 5 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ static PyObject *psyco_adapters = NULL;
int
pysqlite_microprotocols_init(PyObject *module)
{
int res;

/* create adapters dictionary and put it in module namespace */
if ((psyco_adapters = PyDict_New()) == NULL) {
return -1;
}

if (PyModule_AddObject(module, "adapters", psyco_adapters) < 0) {
Py_DECREF(psyco_adapters);
return -1;
}
res = PyModule_AddObjectRef(module, "adapters", psyco_adapters);
Py_DECREF(psyco_adapters);

return 0;
return res;
}


Expand Down
27 changes: 16 additions & 11 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,17 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
return pysqlite_microprotocols_adapt(obj, proto, alt);
}

static void converters_init(PyObject* module)
static int converters_init(PyObject* module)
{
_pysqlite_converters = PyDict_New();
if (!_pysqlite_converters) {
return;
return -1;
}

if (PyModule_AddObject(module, "converters", _pysqlite_converters) < 0) {
Py_DECREF(_pysqlite_converters);
}
return;
int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters);
Py_DECREF(_pysqlite_converters);

return res;
}

static PyMethodDef module_methods[] = {
Expand Down Expand Up @@ -357,12 +357,14 @@ do { \

#define ADD_EXCEPTION(module, name, exc, base) \
do { \
int res; \
exc = PyErr_NewException(MODULE_NAME "." name, base, NULL); \
if (!exc) { \
goto error; \
} \
if (PyModule_AddObject(module, name, exc) < 0) { \
Py_DECREF(exc); \
res = PyModule_AddObjectRef(module, name, exc); \
Py_DECREF(exc); \
if (res == -1) { \
goto error; \
} \
} while (0)
Expand Down Expand Up @@ -417,8 +419,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
Now OptimizedUnicode is an alias for str, so it has no
effect. */
Py_INCREF((PyObject*)&PyUnicode_Type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call looks like a ref leak.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the (now) useless INCREF/DECREF dance.

Copy link
Contributor Author

@erlend-aasland erlend-aasland Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it; thanks!

if (PyModule_AddObject(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type) < 0) {
Py_DECREF((PyObject*)&PyUnicode_Type);
int res = PyModule_AddObjectRef(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type);
Py_DECREF((PyObject*)&PyUnicode_Type);
if (res == -1) {
goto error;
}

Expand All @@ -441,7 +444,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
}

/* initialize the default converters */
converters_init(module);
if (converters_init(module) < 0) {
goto error;
}

error:
if (PyErr_Occurred())
Expand Down