Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
5.15.2
-
None
-
python 3.9.5
archlinux
Description
repeated calls to py_initialize fail. I was trying to build a MWE for another crash similar to but instead I am now running into a different crash here:
#include <Python.h> #include <shiboken.h> #include <QCoreApplication> #include <QStringList> #include <QDir> #include <QDebug> #include <QObject> #include <QPointer> using namespace std; void test() { qWarning() << "init"; Py_Initialize(); QPointer<QObject> timer; { Shiboken::AutoDecRef module(PyImport_ImportModule("__main__")); Shiboken::AutoDecRef globalDict(PyModule_GetDict(module)); Shiboken::AutoDecRef compiled(Py_CompileString("from PySide2 import QtCore\ntimer = QtCore.QTimer()\n", "test.py", Py_file_input)); qWarning() << compiled.isNull(); Shiboken::AutoDecRef ret(PyEval_EvalCode(compiled, globalDict, globalDict)); qWarning() << ret.isNull(); auto pyTimer = PyDict_GetItemString(globalDict, "timer"); qWarning() << pyTimer; auto converter = Shiboken::Conversions::getConverter("QObject*"); qWarning() << converter; QObject *ptr = nullptr; Shiboken::Conversions::pythonToCppPointer(converter, pyTimer, &ptr); qWarning() << ptr; timer = ptr; } qWarning() << timer; Py_Finalize(); qWarning() << "deinit" << timer; } int main(int argc, char** argv) { QCoreApplication app(argc, argv); test(); test(); // << crash return 0; }
when compiled locally with
g++ test.cpp -lpython3.9 -lQt5Core -lshiboken2.cpython-39-x86_64-linux-gnu -I /usr/include/python3.9/ -I /usr/include/shiboken2/ -I /usr/include/qt -I /usr/include/qt/QtCore/ -fPIC -fsanitize=address,undefined -g
triggers this crash (the first round works as expected, second test crashes):
0.000 warning: test[test.cpp:15]: init 0.019 warning: test[test.cpp:24]: false 0.056 warning: test[test.cpp:27]: false 0.056 warning: test[test.cpp:30]: 0x7f8fae5c1900 0.056 warning: test[test.cpp:33]: 0x60600001dfc0 0.056 warning: test[test.cpp:37]: QTimer(0x60400001ee50) 0.056 warning: test[test.cpp:41]: QObject(0x0) 0.061 warning: test[test.cpp:43]: deinit QObject(0x0) 0.061 warning: test[test.cpp:15]: init AddressSanitizer:DEADLYSIGNAL ================================================================= ==298597==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7f8fb56745a1 bp 0x000000000037 sp 0x7ffc1a9cedf0 T0) ==298597==The signal is caused by a READ memory access. ==298597==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used. #0 0x7f8fb56745a1 in pymalloc_alloc Objects/obmalloc.c:1621 #1 0x7f8fb56745a1 in _PyObject_Malloc Objects/obmalloc.c:1640 #2 0x7f8fb56745a1 in PyObject_Malloc Objects/obmalloc.c:685 #3 0x7f8fb56a32d6 in PyUnicode_New Objects/unicodeobject.c:1447 #4 0x7f8fb56a32d6 in unicode_decode_utf8 Objects/unicodeobject.c:5009 #5 0x7f8fb565cbf5 in PyDict_SetItemString Objects/dictobject.c:3505 #6 0x7f8fb573e022 in PyModule_AddObject Python/modsupport.c:656 #7 0x7f8fb573e022 in PyModule_AddIntConstant Python/modsupport.c:668 #8 0x7f8fb57a9519 in PyInit__signal Modules/signalmodule.c:1535 #9 0x7f8fb573147a in _imp_create_builtin Python/import.c:1295 #10 0x7f8fb566a6a6 in cfunction_vectorcall_O Objects/methodobject.c:512 #11 0x7f8fb570c6fb in do_call_core Python/ceval.c:5092 #12 0x7f8fb570c6fb in _PyEval_EvalFrameDefault Python/ceval.c:3580 #13 0x7f8fb5705d60 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:40 #14 0x7f8fb5705d60 in _PyEval_EvalCode Python/ceval.c:4327 #15 0x7f8fb561c8eb in _PyFunction_Vectorcall Objects/call.c:396 #16 0x7f8fb5706c3e in _PyObject_VectorcallTstate Include/cpython/abstract.h:118 #17 0x7f8fb5706c3e in PyObject_Vectorcall Include/cpython/abstract.h:127 #18 0x7f8fb5706c3e in call_function Python/ceval.c:5072 #19 0x7f8fb5706c3e in _PyEval_EvalFrameDefault Python/ceval.c:3518 #20 0x7f8fb561c853 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:40 #21 0x7f8fb561c853 in function_code_fastcall Objects/call.c:330 #22 0x7f8fb561c853 in _PyFunction_Vectorcall Objects/call.c:367 #23 0x7f8fb561fa5c in _PyObject_VectorcallTstate Include/cpython/abstract.h:118 #24 0x7f8fb561fa5c in method_vectorcall Objects/classobject.c:53 #25 0x7f8fb570b5d8 in _PyObject_VectorcallTstate Include/cpython/abstract.h:118 #26 0x7f8fb570b5d8 in PyObject_Vectorcall Include/cpython/abstract.h:127 #27 0x7f8fb570b5d8 in call_function Python/ceval.c:5072 #28 0x7f8fb570b5d8 in _PyEval_EvalFrameDefault Python/ceval.c:3487 #29 0x7f8fb561c853 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:40 #30 0x7f8fb561c853 in function_code_fastcall Objects/call.c:330 #31 0x7f8fb561c853 in _PyFunction_Vectorcall Objects/call.c:367 #32 0x7f8fb5706c3e in _PyObject_VectorcallTstate Include/cpython/abstract.h:118 #33 0x7f8fb5706c3e in PyObject_Vectorcall Include/cpython/abstract.h:127 #34 0x7f8fb5706c3e in call_function Python/ceval.c:5072 #35 0x7f8fb5706c3e in _PyEval_EvalFrameDefault Python/ceval.c:3518 #36 0x7f8fb561c853 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:40 #37 0x7f8fb561c853 in function_code_fastcall Objects/call.c:330 #38 0x7f8fb561c853 in _PyFunction_Vectorcall Objects/call.c:367 #39 0x7f8fb5706c3e in _PyObject_VectorcallTstate Include/cpython/abstract.h:118 #40 0x7f8fb5706c3e in PyObject_Vectorcall Include/cpython/abstract.h:127 #41 0x7f8fb5706c3e in call_function Python/ceval.c:5072 #42 0x7f8fb5706c3e in _PyEval_EvalFrameDefault Python/ceval.c:3518 #43 0x7f8fb561c853 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:40 #44 0x7f8fb561c853 in function_code_fastcall Objects/call.c:330 #45 0x7f8fb561c853 in _PyFunction_Vectorcall Objects/call.c:367 #46 0x7f8fb5706c3e in _PyObject_VectorcallTstate Include/cpython/abstract.h:118 #47 0x7f8fb5706c3e in PyObject_Vectorcall Include/cpython/abstract.h:127 #48 0x7f8fb5706c3e in call_function Python/ceval.c:5072 #49 0x7f8fb5706c3e in _PyEval_EvalFrameDefault Python/ceval.c:3518 #50 0x7f8fb561c853 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:40 #51 0x7f8fb561c853 in function_code_fastcall Objects/call.c:330 #52 0x7f8fb561c853 in _PyFunction_Vectorcall Objects/call.c:367 #53 0x7f8fb561c315 in _PyObject_VectorcallTstate Include/cpython/abstract.h:118 #54 0x7f8fb561c315 in object_vacall Objects/call.c:792 #55 0x7f8fb561df57 in _PyObject_CallMethodIdObjArgs Objects/call.c:883 #56 0x7f8fb57318f5 in import_find_and_load Python/import.c:1771 #57 0x7f8fb57318f5 in PyImport_ImportModuleLevelObject Python/import.c:1872 #58 0x7f8fb56fee79 in builtin___import__ Python/bltinmodule.c:280 #59 0x7f8fb566a8ad in cfunction_call Objects/methodobject.c:539 #60 0x7f8fb561bf57 in _PyObject_MakeTpCall Objects/call.c:191 #61 0x7f8fb561e508 in _PyObject_VectorcallTstate Include/cpython/abstract.h:116 #62 0x7f8fb561e508 in _PyObject_VectorcallTstate Include/cpython/abstract.h:103 #63 0x7f8fb561e508 in _PyObject_CallFunctionVa Objects/call.c:543 #64 0x7f8fb561e508 in PyObject_CallFunction Objects/call.c:565 #65 0x7f8fb5731f51 in PyImport_Import Python/import.c:2073 #66 0x7f8fb572e72d in PyImport_ImportModule Python/import.c:1488 #67 0x7f8fb57a9061 in signal_install_handlers Modules/signalmodule.c:1810 #68 0x7f8fb57a9061 in _PySignal_Init Modules/signalmodule.c:1833 #69 0x7f8fb5745a33 in init_interp_main Python/pylifecycle.c:1015 #70 0x7f8fb574529e in pyinit_main Python/pylifecycle.c:1097 #71 0x7f8fb5744952 in Py_InitializeFromConfig Python/pylifecycle.c:1141 #72 0x7f8fb5744a14 in Py_InitializeEx Python/pylifecycle.c:1172 #73 0x556f8d0f9e75 in test() /tmp/test.cpp:16 #74 0x556f8d0faeef in main /tmp/test.cpp:50 #75 0x7f8fb4042b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) #76 0x556f8d0f9b0d in _start (/tmp/a.out+0xab0d) AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV Objects/obmalloc.c:1621 in pymalloc_alloc