[Python-checkins] python/dist/src/Objects frameobject.c,2.59.6.1,2.59.6.2

tim_one@sourceforge.net tim_one@sourceforge.net
2002年4月12日 22:25:30 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv3938/221/Objects
Modified Files:
 Tag: release22-maint
	frameobject.c 
Log Message:
SF bug 543148: Memory leak with stackframes + inspect.
Put a bound on the number of frameobjects that can live in the
frameobject free_list.
Also fixed on the trunk. I don't intend to backport to 2.1 (too
much work -- lots of cyclic structures leak there).
Index: frameobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.59.6.1
retrieving revision 2.59.6.2
diff -C2 -d -r2.59.6.1 -r2.59.6.2
*** frameobject.c	28 Mar 2002 20:36:50 -0000	2.59.6.1
--- frameobject.c	13 Apr 2002 05:25:28 -0000	2.59.6.2
***************
*** 57,63 ****
--- 57,69 ----
 call depth of more than 20 or 30 is probably already exceptional
 unless the program contains run-away recursion. I hope.
+ 
+ Later, MAXFREELIST was added to bound the # of frames saved on
+ free_list. Else programs creating lots of cyclic trash involving
+ frames could provoke free_list into growing without bound.
 */
 
 static PyFrameObject *free_list = NULL;
+ static int numfree = 0;		/* number of frames currently in free_list */
+ #define MAXFREELIST 200		/* max value for numfree */
 
 static void
***************
*** 92,97 ****
 	Py_XDECREF(f->f_exc_value);
 	Py_XDECREF(f->f_exc_traceback);
! 	f->f_back = free_list;
! 	free_list = f;
 	Py_TRASHCAN_SAFE_END(f)
 }
--- 98,108 ----
 	Py_XDECREF(f->f_exc_value);
 	Py_XDECREF(f->f_exc_traceback);
! 	if (numfree < MAXFREELIST) {
! 		++numfree;
! 		f->f_back = free_list;
! 		free_list = f;
! 	}
! 	else
! 		PyObject_GC_Del(f);
 	Py_TRASHCAN_SAFE_END(f)
 }
***************
*** 246,249 ****
--- 257,262 ----
 	}
 	else {
+ 		assert(numfree > 0);
+ 		--numfree;
 		f = free_list;
 		free_list = free_list->f_back;
***************
*** 476,479 ****
--- 489,494 ----
 		free_list = free_list->f_back;
 		PyObject_GC_Del(f);
+ 		--numfree;
 	}
+ 	assert(numfree == 0);
 }

AltStyle によって変換されたページ (->オリジナル) /