This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Crash after attempt to set the error indicator via PyErr_SetString()
Type: crash Stage:
Components: Interpreter Core Versions: Python 2.4, Python 2.6, Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, gregory.p.smith, iankko, loewis, pitrou, psss
Priority: normal Keywords:

Created on 2009-07-02 16:54 by iankko, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pyexceptions-sample.tar.gz iankko, 2009-07-02 16:54 Python-2.6.2 reproducer
core.31283.bz2 iankko, 2009-07-02 17:00 The whole core file
Messages (2)
msg90026 - (view) Author: Jan Lieskovsky (iankko) Date: 2009-07-02 16:54
Hello guys,

  i am experiencing segmentation fault, when trying to set the
error indicator via the PyErr_SetString() method called from C source.
This occurs for all Python exceptions, as documented in:

    http://docs.python.org/c-api/exceptions.html

Checked Python-2.6.2, also Python-2.4.1 - the crash is present
there (wondering what's wrong with the provided reproducer).

Scenario:
--------
tar xvzf pyexceptions-sample.tar.gz
cd pyexceptions-sample
make
./pyexceptionssample -> 
Segmentation fault (core dumped)

Note: Doesn't matter if compiled with libpython2.6.a or libpython2.4.so,
      the crash is still there.

Here is the most interesting part of the backtrace (the whole
coredump also attached).

gdb ./pyexceptions-sample core.31283

Core was generated by `./pyexceptions-sample'.
Program terminated with signal 11, Segmentation fault.
[New process 31283]
#0  PyErr_Restore (type=0x60000000000058f0, value=0x2000000000435030,
traceback=0x0) at Python/errors.c:39
39		oldtype = tstate->curexc_type;

(gdb) bt
#0  PyErr_Restore (type=0x60000000000058f0, value=0x2000000000435030,
traceback=0x0) at Python/errors.c:39
#1  0x4000000000125180 in PyErr_SetString (exception=0x60000000000058f0,
string=<value optimized out>) at Python/errors.c:57
#2  0x4000000000005eb0 in check_value ()
#3  0x4000000000006670 in main ()

(gdb) info args
type = (PyObject *) 0x60000000000058f0
value = (PyObject *) 0x2000000000435030
traceback = (PyObject *) 0x0

(gdb) info locals
tstate = (PyThreadState *) 0x0
oldtype = <value optimized out>
oldvalue = <value optimized out>
oldtraceback = <value optimized out>

(Looks like NULL ptr dereference in tstate = (PyThreadState *)).

Could you please have a look?

Thanks && regards, Jan.
--
Jan iankko Lieskovsky
msg90032 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-07-02 19:09
This bug tracker is not a place to obtain help. If it is primarily help
that you are after (which it seems to be from your last question), I
recommend that we close the issue, and you ask for help elsewhere.

Most likely, the error happens at a point in the code where there is no
thread state. You have to find out why that is - it could be either that
there is legitimately no thread state, in which case you shouldn't call
Python API, or it might be that the thread state was lost somehow, in
which case you should find out where it got lost.
History
Date User Action Args
2022-04-11 14:56:50adminsetgithub: 50651
2009-07-02 21:01:10benjamin.petersonsetstatus: open -> closed
resolution: not a bug
2009-07-02 19:09:33loewissetnosy: + loewis
messages: + msg90032
2009-07-02 17:04:11iankkosetnosy: + gregory.p.smith, pitrou, benjamin.peterson, psss
2009-07-02 17:00:18iankkosetfiles: + core.31283.bz2
2009-07-02 16:54:25iankkocreate