[SciPy-dev] segfault in leastsq

Stefan van der Walt stefan at sun.ac.za
Tue May 16 08:37:13 EDT 2006


Running this code through Valgrind (on numpy r2503) reveals two
problems.  The first, in __minpack.h, is the one that causes your
segfault:

==17580== Invalid read of size 4
==17580==    at 0x653A2D2: minpack_lmdif (__minpack.h:452)
==17580==    by 0x80B62C6: PyEval_EvalFrame (in /usr/bin/python2.4)
==17580==    by 0x80B771E: PyEval_EvalCodeEx (in /usr/bin/python2.4)
==17580==    by 0x80B6F92: PyEval_EvalFrame (in /usr/bin/python2.4)
==17580==    by 0x80B771E: PyEval_EvalCodeEx (in /usr/bin/python2.4)
==17580==    by 0x80B7964: PyEval_EvalCode (in /usr/bin/python2.4)
==17580==    by 0x80D94CB: PyRun_FileExFlags (in /usr/bin/python2.4)
==17580==    by 0x80D976B: PyRun_SimpleFileExFlags (in /usr/bin/python2.4)
==17580==    by 0x8055B32: Py_Main (in /usr/bin/python2.4)
==17580==    by 0x4080EA1: __libc_start_main (in /lib/tls/i686/cmov/libc-2.3.6.so)
==17580==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==17580==
==17580== Process terminating with default action of signal 11 (SIGSEGV)

But then I also see the following, probably unrelated problem, which
is caused by numpy's handling of scalars:

==17293== 48 (40 direct, 8 indirect) bytes in 1 blocks are definitely lost in loss record 14 of 125
==17293==    at 0x401C422: malloc (vg_replace_malloc.c:149)
==17293==    by 0x48E4D6A: array_alloc (arrayobject.c:5582)
==17293==    by 0x48EEA73: PyArray_NewFromDescr (arrayobject.c:4393)
==17293==    by 0x48FFC45: PyArray_FromArray (arrayobject.c:6414)
==17293==    by 0x490710A: PyArray_FromAny (arrayobject.c:6843)
==17293==    by 0x65961E9: minpack_lmdif (__minpack.h:438)
==17293==    by 0x80B62C6: PyEval_EvalFrame (in /usr/bin/python2.4)
==17293==    by 0x80B771E: PyEval_EvalCodeEx (in /usr/bin/python2.4)
==17293==    by 0x80B6F92: PyEval_EvalFrame (in /usr/bin/python2.4)
==17293==    by 0x80B771E: PyEval_EvalCodeEx (in /usr/bin/python2.4)
==17293==
==17293==
==17293== 296 bytes in 23 blocks are definitely lost in loss record 92 of 125
==17293==    at 0x401C422: malloc (vg_replace_malloc.c:149)
==17293==    by 0x48D74EA: gentype_alloc (scalartypes.inc:339)
==17293==    by 0x48FA8ED: PyArray_ScalarFromObject (scalartypes.inc:293)
==17293==    by 0x4F54AFF: _int_convert_to_ctype (scalarmathmodule.c:2025)
==17293==    by 0x4F646F2: int_richcompare (scalarmathmodule.c:2038)
==17293==    by 0x807CE1E: (within /usr/bin/python2.4)
==17293==    by 0x807E450: PyObject_RichCompare (in /usr/bin/python2.4)
==17293==    by 0x80B2109: PyEval_EvalFrame (in /usr/bin/python2.4)
==17293==    by 0x80B771E: PyEval_EvalCodeEx (in /usr/bin/python2.4)
==17293==    by 0x80FC03C: (within /usr/bin/python2.4)

Hope this helps pin it down.

Regards
Stéfan

On Tue, May 16, 2006 at 08:07:54AM -0400, Neal Becker wrote:
> from scipy.optimize import leastsq
> from math import exp
> 
> def f (x):
>     print x
>     return (exp (x) - exp (0.5))
> 
> print leastsq (f, 0.1)
> 
> Python 2.4.2 (#1, Feb 12 2006, 03:45:41) 
> [GCC 4.1.0 20060210 (Red Hat 4.1.0-0.24)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> ## working on region in file /usr/tmp/python-CzAVPU.py...
> [ 0.1]
> [ 0.1]
> 
> Process Python segmentation fault
> scipy-0.4.8-4
> numpy-0.9.6-1.fc5




More information about the SciPy-Dev mailing list