Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Crash report
What happened?
When usingctypes with a function which returns aPyObject *, usingrestypectypes.py_object, and the function returnsNULL, there's aPy_DECREF of the result, leading to a segfault:
importctypesPyErr_Occurred=ctypes.pythonapi.PyErr_OccurredPyErr_Occurred.argtypes= []PyErr_Occurred.restype=ctypes.py_objectPyErr_Occurred()
The issue lies inGetResult: whenO_get is the result handler, it callsPy_DECREF on the result value, even though that can beNULL.O_get handles theNULL case correctly, setting an exception if none was set, and passing on theNULL. Code after thePy_DECREF inGetResult also handles theNULL case correctly, so changing thePy_DECREF into aPy_XDECREF makes things work.
Pull request incoming.
CPython versions tested on:
CPython 3.10, CPython 3.13, CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0a7+ (heads/main-dirty:deda47d6e18, Apr 11 2025, 20:18:59) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)]