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: Py_XDECREF on PyUnicodeobject raises SIGSEGV signal
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Khalil, serhiy.storchaka
Priority: normal Keywords:

Created on 2019-05-16 13:20 by Khalil, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg342642 - (view) Author: Khalil (Khalil) Date: 2019-05-16 13:20
I Have a set of callbacks from a C extension to a Python code and I noticed that when I report a unicode string to the Python code, and use the Py_XDECREF on it then whole application crashes with the SIGSEGV signal.This is a snippet of the codes:

/***************************/
....
PyObject *MyString = PyUnicode_FromString("BlaBla");
PyTuple_SetItem(MyTuple, 0, MyString);
PyObject_CallObject(callback, PyTuple);

Py_XDECREF(MyString);
Py_XDECREF(MyTuple);
...
/***********************************/

when I create my string within the set item then it works fine, like below:
....
PyTuple_SetItem(MyTuple, 0, PyUnicode_FromString("BlaBla"));
PyObject_CallObject(callback, PyTuple);
Py_XDECREF(MyTuple);
...
msg342644 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-05-16 13:33
PyTuple_SetItem() steals a reference to the added item. You should not call Py_XDECREF() for it.
History
Date User Action Args
2022-04-11 14:59:15adminsetgithub: 81119
2019-05-16 13:33:40serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg342644

resolution: not a bug
stage: resolved
2019-05-16 13:20:46Khalilcreate