[Python-bugs-list] [ python-Bugs-572567 ] Memory leak in object comparison

noreply@sourceforge.net noreply@sourceforge.net
Mon, 24 Jun 2002 04:21:21 -0700


Bugs item #572567, was opened at 2002-06-22 14:17
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=572567&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Kevin Jacobs (jacobs99)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Memory leak in object comparison

Initial Comment:
There is a rather obscure memory leak caused
by a missing Py_DECREF one of the comparison
function wrappers in typeobject.c.  It is obscure only 
because it inflates the reference count on methods,
which is why it has gone unnoticed since its inital
checkin on 8/15/2001.  Unfortunately, one of my
meta-class experiments triggers this code on
many ephemoral class instances, and thus leaks 
heaping chunks of memory (or a heaping number of 
little chunks, if you like).

I've attached the simple one line fix, which should
be applied to the next 2.2.x release, and certainly
to the 2.3 CVS tree.  To make myself really useful, 
I've also audited the rest of typeobject.c to make sure 
that all users of 'lookup_method', the source of the 
leaked reference, properly handle its results.


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

>Comment By: Kevin Jacobs (jacobs99)
Date: 2002-06-24 06:21

Message:
Logged In: YES 
user_id=459565

I've attached a test case that demonstrates and
detects the leak.  There is also a stack trace and 
the code that generates the leaked objects included at the 
bottom of the test case.


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

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-06-24 03:41

Message:
Logged In: YES 
user_id=80475

I concur.

And, yes, it would it great to have a unittest that fails 
before the patch and works afterward (perhaps using the 
GC module to demonstrate the leak).

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

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-06-23 22:31

Message:
Logged In: YES 
user_id=33168

Your patch seems correct. There is an INCREF
in lookup_maybe() which is called by lookup_method().
Also, other places which call lookup_method() do the DECREF.

Could you please attach a test case which triggers this
bug?Thanks.

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

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