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: Reference leak in filter()
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: mhammond, tim.peters
Priority: normal Keywords:

Created on 2001-05-21 07:37 by mhammond, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (2)
msg4822 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2001-05-21 07:37
I appear to have struck a reference leak in filter:

>>> l=range(10)
[5552 refs]
>>> l2=filter(lambda m:m, l)
[5571 refs]
>>> l2=filter(lambda m:m, l)
[5574 refs]

etc - always dropping 3 references.

The following patch fixes it:

Index: bltinmodule.c
=======================================================
============
RCS 
file: /cvsroot/python/python/dist/src/Python/bltinmodul
e.c,v
retrieving revision 2.207
diff -c -r2.207 bltinmodule.c
*** bltinmodule.c	2001/05/14 12:17:34	2.207
--- bltinmodule.c	2001/05/21 07:37:07
***************
*** 264,269 ****
--- 264,270 ----
  	if (j < len && PyList_SetSlice(result, j, len, 
NULL) < 0)
  		goto Fail_result_it;
  
+ 	Py_DECREF(it);
  	return result;
  
  Fail_result_it:


msg4823 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-05-21 08:08
Logged In: YES 
user_id=31435

So don't use filter <wink>.

Oh, all right, it's a bug.  Thanks for enduring the pain!
Checked in as Python/bltinmodule.c, new revision: 2.208.
History
Date User Action Args
2022-04-10 16:04:04adminsetgithub: 34525
2001-05-21 07:37:41mhammondcreate