This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Memory leak in object comparison
Type: Stage:
Components: Interpreter Core Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: jacobs99, nnorwitz, rhettinger
Priority: normal Keywords:

Created on 2002-06-22 19:17 by jacobs99, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
typeobject.diff jacobs99, 2002-06-22 19:17 One line patch to fix a memoty leak in typeobject.c
show_leak.py jacobs99, 2002-06-24 11:22 Test case, stack trace, and source of leak
Messages (5)
msg11303 - (view) Author: Kevin Jacobs (jacobs99) Date: 2002-06-22 19:17
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.
msg11304 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-06-24 03:31
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.
msg11305 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-06-24 08:41
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).
msg11306 - (view) Author: Kevin Jacobs (jacobs99) Date: 2002-06-24 11:21
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.
msg11307 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-06-24 13:26
Logged In: YES 
user_id=80475

Committed patch as:
test_descr.py  1.144 and 1.113.4.19
typeobject.c 2.157 and 2.126.4.17

Closing bug.
History
Date User Action Args
2022-04-10 16:05:26adminsetgithub: 36786
2002-06-22 19:17:25jacobs99create