Unverified Commit 3abadbb2 by Victor M. Alvarez Committed by GitHub

Fix segfault in Python 3.12b4 (#238)

In `flo_read` and `flo_write` there were calls to `Py_DECREF` after releasing the GIL.

Closes #237
parent 0030658c
...@@ -1394,10 +1394,12 @@ static size_t flo_read( ...@@ -1394,10 +1394,12 @@ static size_t flo_read(
PyObject* bytes = PyObject_CallMethod( PyObject* bytes = PyObject_CallMethod(
(PyObject*) user_data, "read", "n", (Py_ssize_t) size); (PyObject*) user_data, "read", "n", (Py_ssize_t) size);
if (bytes == NULL)
{
PyGILState_Release(gil_state); PyGILState_Release(gil_state);
return i;
}
if (bytes != NULL)
{
Py_ssize_t len; Py_ssize_t len;
char* buffer; char* buffer;
...@@ -1406,17 +1408,14 @@ static size_t flo_read( ...@@ -1406,17 +1408,14 @@ static size_t flo_read(
if (result == -1 || (size_t) len < size) if (result == -1 || (size_t) len < size)
{ {
Py_DECREF(bytes); Py_DECREF(bytes);
PyGILState_Release(gil_state);
return i; return i;
} }
memcpy((char*) ptr + i * size, buffer, size); memcpy((char*) ptr + i * size, buffer, size);
Py_DECREF(bytes); Py_DECREF(bytes);
} PyGILState_Release(gil_state);
else
{
return i;
}
} }
return count; return count;
...@@ -1444,12 +1443,11 @@ static size_t flo_write( ...@@ -1444,12 +1443,11 @@ static size_t flo_write(
(PyObject*) user_data, "write", "s#", (char*) ptr + i * size, size); (PyObject*) user_data, "write", "s#", (char*) ptr + i * size, size);
#endif #endif
Py_XDECREF(result);
PyGILState_Release(gil_state); PyGILState_Release(gil_state);
if (result == NULL) if (result == NULL)
return i; return i;
Py_DECREF(result);
} }
return count; return count;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment