Memory leak ??

A.M. Kuchling amk at amk.ca
Thu Jul 10 10:42:51 EDT 2003


On Thu, 10 Jul 2003 14:34:05 +0200, 
	Kim Petersen <kp at kyborg.dk> wrote:
> Using python-2.2.2-26 on RH9 (shrike) x86 -fully patched
> 
> The following program slowly eats up more and more memory when run on
> large datasets... can anyone tell what the trouble is?

Your code uses eval(), which is pretty heavyweight because it has to
tokenize, parse, and then evaluate the string.  There have been a few memory
leaks in eval(), and perhaps you're running into one of them.  Try using
int() or float() to convert strings to numbers instead of eval.  As a bonus,
your program will be faster and much more secure (could an attacker tweak 
your logfiles so you end up eval()ing os.unlink('/etc/passwd')?).

In general, using eval() is almost always a mistake; few programs need to 
take arbitrary expressions as input.

--amk




More information about the Python-list mailing list