This program makes Python segfault - no other does

Juho Saarikko sorry at but.no.spam
Mon May 17 12:42:53 EDT 2004


On Mon, 17 May 2004 10:57:55 -0400, Terry Reedy wrote:

> Based on posts over several years, seq faults most often arise from
> 1. buggy compilers, especially at 'higher' optimization settings

Compiler is gcc 2.95.4, with the debug optimization ("make OPT=-g").

> 2. buggy compiled extensions

There seems to be one potential segfault waiting there, if PostGreSQL
gives suitably malformed Bytea string, but it has nothing to do with this.

> 3. byte code fiddling
> and only occasionally from
> 4. Python interpreter bugs
> which the developers consider high priority for squashing.

Well, what do you think, should I report this ? Because I can't find
anything wrong with the extension code - not that my C skills are that
great, but still.

>> Specifically, I'm wondering if my habit of reusing old variable names in
> a
>> function once they are no longer needed might be causing the trouble;
>> maybe it causes confusion on the variable type ?
> 
> Very dubious to me; at worst you should get an exception with traceback.

Yup, wasn't that; there's something fishy happening at Python memory
management code, apparently.

>> So, here's the program. Does anyone know what's wrong with it ?
> 
> Since you don't seem to be fiddling with internals, there is no way I know
> to eyeball the code and tell which line is doing the 'impossible'.  So I

The conn.getvalue() -lines. Specifically, getvalue() on a Bytea field
seems to be the cause of the problem, triggering the segfault on some
lines.

> think it up to you to determing the offending line by uncommenting print
> statements and adding more as needed.  Then see if you can reduce the
> program and still get segfaults.

I did, that's why the print lines are there. I'm sorry I didn't think to
include the info from the start... Anyway, here's gdb stacktrace, if
anyone's interested. The problem is not in unQuoteBytea, which works fine
untill it tries to discard some temporary variables, at which point,
kaboom. That would seem to indicate either line #2 or #3, but this is the
first time I've used a debugger, so I might be quite wrong.

#0  0x400c4c1b in free () from /lib/libc.so.6
#1  0x400c4aa3 in free () from /lib/libc.so.6
#2  0x0807ff2e in PyObject_Free (p=0x81d7240) at Objects/obmalloc.c:774
#3  0x0807f5a6 in PyMem_Free (p=0x81d7240) at Objects/object.c:2111
#4  0x4023a2d4 in unQuoteBytea (sin=0x81dd2ec ">nemo wrote:") at libpqmodule.c:417
#5  0x40243c2f in libPQgetvalue (self=0x401dfe00, args=0x401ea74c) at pgresult.c:630
#6  0x080fede0 in PyCFunction_Call (func=0x401eabcc, arg=0x401ea74c, kw=0x0) at Objects/methodobject.c:73
#7  0x080b7d4a in call_function (pp_stack=0xbffff2f8, oparg=2) at Python/ceval.c:3439
#8  0x080b50e0 in eval_frame (f=0x81dcbd4) at Python/ceval.c:2116
#9  0x080b7ff3 in fast_function (func=0x401ed294, pp_stack=0xbffff448, n=2, na=2, nk=0) at Python/ceval.c:3518
#10 0x080b7e2d in call_function (pp_stack=0xbffff448, oparg=2) at Python/ceval.c:3458
#11 0x080b50e0 in eval_frame (f=0x818d16c) at Python/ceval.c:2116
#12 0x080b669d in PyEval_EvalCodeEx (co=0x401bade0, globals=0x4018b79c, locals=0x4018b79c, args=0x0, argcount=0, kws=0x0, kwcount=0,
    defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2663
#13 0x080b16f0 in PyEval_EvalCode (co=0x401bade0, globals=0x4018b79c, locals=0x4018b79c) at Python/ceval.c:537
#14 0x080da8e4 in run_node (n=0x40174350, filename=0xbffff83b "decode_uu.py", globals=0x4018b79c, locals=0x4018b79c, flags=0xbffff670)
    at Python/pythonrun.c:1265
#15 0x080da880 in run_err_node (n=0x40174350, filename=0xbffff83b "decode_uu.py", globals=0x4018b79c, locals=0x4018b79c, flags=0xbffff670)
    at Python/pythonrun.c:1252
#16 0x080da843 in PyRun_FileExFlags (fp=0x8142908, filename=0xbffff83b "decode_uu.py", start=257, globals=0x4018b79c, locals=0x4018b79c,
    closeit=1, flags=0xbffff670) at Python/pythonrun.c:1243
#17 0x080d97c6 in PyRun_SimpleFileExFlags (fp=0x8142908, filename=0xbffff83b "decode_uu.py", closeit=1, flags=0xbffff670)
    at Python/pythonrun.c:862
#18 0x080d9065 in PyRun_AnyFileExFlags (fp=0x8142908, filename=0xbffff83b "decode_uu.py", closeit=1, flags=0xbffff670)
    at Python/pythonrun.c:659
#19 0x08055220 in Py_Main (argc=2, argv=0xbffff734) at Modules/main.c:415
#20 0x080549e6 in main (argc=2, argv=0xbffff734) at Modules/python.c:23




More information about the Python-list mailing list