[Python-Dev] Py_DECREF(m) on PyInit_xxx() failure? (original) (raw)

Serhiy Storchaka storchaka at gmail.com
Thu Nov 30 11:00:32 EST 2017


30.11.17 17:42, Victor Stinner пише:

CPython has many C extensions with non-trivial PyInitxxx() functions which has to handle failures. A few modules use "PyDECREF(m); retutrn NULL;", but most functions only do "return NULL;". Is it a reference leak or not?

Example from Modules/posixmodule.c: v = convertenviron(); PyXINCREF(v); if (v == NULL || PyModuleAddObject(m, "environ", v) != 0) return NULL; PyDECREF(v); Does this code leak a reference on m? ... Oh, and maybe also leaks a reference on v?

https://mail.python.org/pipermail/python-dev/2016-April/144359.html https://bugs.python.org/issue26871



More information about the Python-Dev mailing list