[Python-modules-team] Bug#505999: python-numpy: memory leak in exponentiation
Jiri Baum
jiri at baum.com.au
Mon Nov 17 16:47:27 UTC 2008
Package: python-numpy
Version: 1:1.1.0-3
Severity: minor
Raising zero to a negative power sometimes leaks memory, depending on the
types involved. While this is easy to work around (check for zero and deal
with it separately), it shouldn't happen.
In particular, with the following combinations of types (where the base is
0 and the exponent is -3 or -3.5), one object is leaked:
float ** numpy.float64
int ** numpy.float64
int ** numpy.int32
int ** numpy.int64
numpy.float32 ** numpy.float32
numpy.float64 ** float
numpy.float64 ** int
numpy.float64 ** numpy.float32
numpy.float64 ** numpy.float64
numpy.float64 ** numpy.int32
numpy.float64 ** numpy.int64
numpy.int32 ** int
numpy.int32 ** numpy.int32
numpy.int64 ** int
numpy.int64 ** numpy.int32
numpy.int64 ** numpy.int64
(In addition, float ** numpy.int32 raises an exception; however, strictly
speaking, that would be a separate issue.)
Code to reproduce this is enclosed below.
-- System Information:
Debian Release: lenny/sid
APT prefers testing
APT policy: (500, 'testing'), (500, 'stable')
Architecture: i386 (i686)
Kernel: Linux 2.6.24-1-686 (SMP w/1 CPU core)
Locale: LANG=en_AU, LC_CTYPE=en_AU (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash
Versions of packages python-numpy depends on:
ii libblas3gf [libblas.so.3gf] 1.2-2 Basic Linear Algebra Subroutines 3
ii libc6 2.7-15 GNU C Library: Shared libraries
ii libgcc1 1:4.3.2-1 GCC support library
ii libgfortran3 4.3.2-1 Runtime library for GNU Fortran ap
ii liblapack3gf [liblapack.so.3g 3.1.1-1 library of linear algebra routines
ii python 2.5.2-3 An interactive high-level object-o
ii python-central 0.6.8 register and build utility for Pyt
python-numpy recommends no packages.
Versions of packages python-numpy suggests:
pn python-numpy-dbg <none> (no description available)
pn python-numpy-doc <none> (no description available)
-- no debconf information
-- Code to reproduce the problem:
#!/usr/bin/python
import gc, numpy
def mem():
gc.collect()
return len(gc.get_objects())
for zt in int, float, numpy.int32, numpy.int64, numpy.float32, numpy.float64:
z = zt(0)
for pt in int, float, numpy.int32, numpy.int64, numpy.float32, numpy.float64:
if zt in (int, float) and pt in (int, float):
continue
p = pt(-3.5)
try:
before = mem()
z**p
if mem()>before:
print 'leak: ', type(z), '**', type(p)
else:
print 'OK: ', type(z), '**', type(p)
except:
print 'error:', type(z), '**', type(p)
More information about the Python-modules-team
mailing list