[ python-Bugs-984722 ] Py_BuildValue loses reference counts on error

SourceForge.net noreply at sourceforge.net
Sat Jul 3 16:19:26 EDT 2004


Bugs item #984722, was opened at 2004-07-03 20:19
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=984722&group_id=5470

Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Pete Shinners (shredwheat)
Assigned to: Nobody/Anonymous (nobody)
Summary: Py_BuildValue loses reference counts on error

Initial Comment:
Py_BuildValue has the convenient "N" type argument to
take a PyObject* without a reference count. To the
programmer this means your are transferring the object
ownership to the Py_BuildValue function (and the tuple
it creates).

If Py_BuildValue encounters an error processing an
argument it aborts and returns NULL. But the remaining
arguments are ignored. Therefore objects are leaked
from a leftover reference count.

>From looking at the code in Python/modsupport.c it
looks like a reasonable solution would be to insert a
Py_None into the tuple/list/dict being created and
internally set some sort of error flag. When the
function is returning it would check the error flag and
if set, Py_DECREF the created object and return NULL.

At first this may seem like a lot of work to do when we
already know the function will fail. But it is no more
work than we would be doing when the function succeeeds.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=984722&group_id=5470



More information about the Python-bugs-list mailing list