schrodinger / pymol-open-source

Open-source foundation of the user-sponsored PyMOL molecular visualization system.
https://pymol.org/
Other
1.2k stars 281 forks source link

Fix GIL for get_object_ttt and friends #285

Closed speleo3 closed 1 year ago

speleo3 commented 1 year ago

The following functions were releasing the GIL and then calling Python functions:

Fixed by either moving the Python calls outside the unblocked API context, or by using a blocked API context.

Observed as a crash after clicking the "Properties" dialog button, which calls cmd.get_object_ttt.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==46349==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x7f09b5d253d3 bp 0x000000000010 sp 0x7ffed0cf7a80 T0)
==46349==The signal is caused by a READ memory access.
==46349==Hint: address points to the zero page.
    #0 0x7f09b5d253d3 in PyList_New (/usr/lib/libpython3.10.so.1.0+0x1253d3)
    #1 0x7f09b22aa62f in PConvFloatArrayToPyList(float const*, int, bool) layer1/PConv.cpp:956
    #2 0x7f09b290a691 in CmdGetObjectTTT(_object*, _object*) layer4/Cmd.cpp:4604

Likely also the reason for the crash reported in https://github.com/Pymol-Scripts/Pymol-script-repo/pull/129 which has a stack trace with CmdTransformSelection.

JarrettSJohnson commented 1 year ago

Great catch. Thanks for the PR!