PyArg_ParseTuple O format semantics

Tim Peters tim.one at home.com
Sat Sep 8 23:23:11 EDT 2001


[Tim]
> News to me, and I see nothing about that in the CVS log.  The only 2.0.1
> patch to getargs.c plugged a memory leak in vgetargskeywords(); it was
> leaving the refcounts on names of keyword arguments too high,
> when iterating over a keyword dict.

[Robin Becker]
> I guess that might be it. I suppose if anyone had taken action to correct
> the memory leak then when it was fixed --> 2.0.1 then their extra DECREF
> would be wrong.

Yes, that would cause problems indeed.  BTW, the Subject line was
misleading, because this really has to do with PyArg_ParseTupleAndKeywords,
and is specific to the "keywords" part of that.  And I was incorrect in
saying it left the refcount on the name of the keyword arg too high -- it
actually left the refcount on the returned object too high.

If you believed the docs and treated the return value as a borrowed
reference, then you used to have a memory leak and don't anymore.  It's
probably rarely a serious leak, else the bug wouldn't have gone undetected
for so long (years).  Here's the original patch that fixed it:

http://mail.python.org/pipermail/python-checkins/2000-December/014550.html

in response to this October 2000 bug report:

http://sf.net/tracker/?group_id=5470&atid=105470&func=detail&aid=219862





More information about the Python-list mailing list