New submission from squidevil:
Expected behavior:
Calling Py_BuildValue with a 'N' argument should take ownership of the N
object, and on failure (returns NULL), call Py_DECREF() on any N argument. The
documentation explicitly says that this is the intended usage:
"N": Same as "O", except it doesn't increment the reference count on the
object. Useful when the object is created by a call to an object constructor in
the argument list.
Actual behavior:
N objects appear to be abandoned/leaked in some cases.
Example: PyBuildValue("iN", 0, obj);
* calls _Py_BuildValue_SizeT via macro
* calls va_build_value (in modsupport.c)
* calls do_mktuple [0]
* [0] first calls v = PyTuple_New(n=2). If this fails, it returns NULL, leaking
obj.
* if [0] creates the tuple v, then it goes on to populate the values in the
tuple.
* [0] calls do_mkvalue() to create the "i=0" object. If this fails, obj is
never Py_DECREF()'ed.
Many other leaks are possible, as long as at least one allocation occurs prior
to the processing of the N arguments.
------
components: Interpreter Core
messages: 258708
nosy: squidevil
priority: normal
severity: normal
status: open
title: Py_BuildValue may leak 'N' arguments on PyTuple_New failure
type: resource usage
versions: Python 2.7
___
Python tracker
<http://bugs.python.org/issue26168>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com