[issue26168] Py_BuildValue may leak 'N' arguments on PyTuple_New failure

2016-01-29 Thread squidevil

squidevil added the comment:

Martin Panter: You're right.  The DECREF on v when itemfailed will decref the N 
object and prevent the leak.  My original analysis was wrong on that count.

You're right, do_mklist and do_mkdict (in 2.7.11 at least) have similar 
problems, bailing after list or dict creation failure, without continuing to 
process the rest of the items.

--

___
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



[issue26168] Py_BuildValue may leak 'N' arguments on PyTuple_New failure

2016-01-29 Thread squidevil

squidevil added the comment:

It looks like this patch is against the "default" cpython (3.x) branch.  The 
2.7 branch is missing the if(itemfailed) code in do_mktuple whose else clause 
was modified by the patch.

It looks like some of this needs to be backported to 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



[issue26168] Py_BuildValue may leak 'N' arguments on PyTuple_New failure

2016-01-20 Thread squidevil

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