[python-ldap] Suspected memory leak in Modules/errors.c:LDAPerr

Bradley McCandless bradskins at gmail.com
Wed Dec 7 23:11:00 CET 2011


Hello,

Just removing the DECREF on line on line 129 of errors.c solves the issue.

http://fedorapeople.org/~dmalcolm/gcc-python-plugin/2011-12-07/errors.c.LDAPinit_errors-refcount-errors.html

>From #pypy.irc.freenode.net:

*exarku <member:exarkun>n: *brads <member:brads>: So, you can point out
that errors.c:129 should not be Py_DECREF'ing the exception class, because
the module re-uses the exception class later on.

*exarkun <member:exarkun>*: brads <member:brads>: And it only works on
CPython by accident

-brad


On Wed, Dec 7, 2011 at 2:41 PM, David Malcolm <dmalcolm at redhat.com> wrote:

> I'm running an experimental static analysis tool [1] over python-ldap,
> and it discovered what looks like a real reference leak:
>
> Modules/errors.c: In function ‘LDAPerr’,
> if it executes this code:
>        else
>                PyErr_SetObject(LDAPexception_class,
>                    Py_BuildValue("{s:i}", "errnum", errnum));
>
> then Py_BuildValue returns a new dictionary with refcount 1, owned by
> the caller; PyErr_SetObject adds a new ref; the first ref is leaked;
> hence the dictionary is leaked every time
>
> HTML version of the above attached.
>
> Having said that, it looks like this branch is only followed when
> receiving an unexpected error ID.
>
> Hope this is helpful
> Dave
>
>
> [1] http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
>
> _______________________________________________
> python-ldap mailing list
> python-ldap at python.org
> http://mail.python.org/mailman/listinfo/python-ldap
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20111207/997aa2ca/attachment-0001.html>


More information about the python-ldap mailing list