Apparent eval() leak for python 2.3.5

John Marshall John.Marshall at ec.gc.ca
Fri Feb 17 13:21:31 EST 2006


Hi,

I am reposting this message from python-dev.

Could someone please test the code below
to verify that there is indeed a problem
with eval() under python 2.3.5. I have
rebuilt python 2.3.5 under the latest debian
and under RH 7.3 (in case the problem is
in system libraries).

The following code causes the virtual memory
allocation to constantly increase until there
is no more memory left (the VIRT column of the
'top' utility display).

-----
#! /usr/bin/env python
#
# evalleak.py

def builddict():
     d = {}
     for i in xrange(10000):
         d[i] = { "int": 0, "str": "nada", "dict": {} }
     return d

if __name__ == "__main__":
     d = builddict()
     st = str(d)
     print "len(st): %d" % len(st)
     while 1:
         d = eval(st)
-----

Thanks,
John



More information about the Python-list mailing list