Skip to content

Incorrect usage of Python API leads to SegFault #144

Description

@asenchenko

SIP wrapper for CtVideo::Image::buffer does not use python API correct.

Macros Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS - releases/acquires python GIL. Releasing the GIL from extension code
According to the source code PyBytes_FromStringAndSize calls _PyBytes_FromSize line 134
_PyBytes_FromSize calls PyObject_Malloc. line 102

Documentation states that the GIL must be held when using these functions. Object allocators.

Code below show that PyBytes_FromStringAndSize is called with release GIL.

` SIP_PYOBJECT buffer() const;
%MethodCode

Py_BEGIN_ALLOW_THREADS
const char* buffer = sipCpp->buffer();
SIP_SSIZE_T size = sipCpp->size();
if (buffer)
sipRes = PyBytes_FromStringAndSize(buffer, size);
else
sipRes = Py_None;
Py_END_ALLOW_THREADS
%End`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions