[Python-Dev] Memory leaks?
Guido van Rossum
Wed, 25 Jul 2001 10:55:51 -0400
> I'm a bit curious about the memory handling of the Py_InitModule4...
> When adding methods, if PyCFunction_New fails, NULL is returned
> without the module object being DECREF'd, and similarly, if the
> PyDict_SetItemString fails, NULL is returned without neither module
> object nor function object being DECREF'd.
> Is this a problem, or is this taken care of somewhere else?
The first one is not a problem. The module 'm' is received from
PyImport_AddModule(), which (in a comment in the source) emphasizes
that the return value does not have its reference count incremented.
Instead, the module is kept alive because it is stored in sys.modules.
The second one should really DECREF v when PyDict_SetItemString()
fails. Ditto for the docstring.
I've added a low-priority bug report, because this is very unlikely to
--Guido van Rossum (home page: http://www.python.org/~guido/)