Commit 197651b4 authored by Richard Oudkerk's avatar Richard Oudkerk

Issue #10133: Make multiprocessing deallocate buffer if socket read fails.

Patch by Hallvard B Furuseth.
parent 2a2ce4f6
...@@ -70,6 +70,9 @@ Core and Builtins ...@@ -70,6 +70,9 @@ Core and Builtins
Library Library
------- -------
- Issue #10133: Make multiprocessing deallocate buffer if socket read
fails. Patch by Hallvard B Furuseth.
- Issue #13854: Make multiprocessing properly handle non-integer - Issue #13854: Make multiprocessing properly handle non-integer
non-string argument to SystemExit. non-string argument to SystemExit.
......
...@@ -117,7 +117,7 @@ static Py_ssize_t ...@@ -117,7 +117,7 @@ static Py_ssize_t
conn_recv_string(ConnectionObject *conn, char *buffer, conn_recv_string(ConnectionObject *conn, char *buffer,
size_t buflength, char **newbuffer, size_t maxlength) size_t buflength, char **newbuffer, size_t maxlength)
{ {
int res; Py_ssize_t res;
UINT32 ulength; UINT32 ulength;
*newbuffer = NULL; *newbuffer = NULL;
...@@ -132,20 +132,23 @@ conn_recv_string(ConnectionObject *conn, char *buffer, ...@@ -132,20 +132,23 @@ conn_recv_string(ConnectionObject *conn, char *buffer,
if (ulength > maxlength) if (ulength > maxlength)
return MP_BAD_MESSAGE_LENGTH; return MP_BAD_MESSAGE_LENGTH;
if (ulength <= buflength) { if (ulength > buflength) {
Py_BEGIN_ALLOW_THREADS *newbuffer = buffer = PyMem_Malloc((size_t)ulength);
res = _conn_recvall(conn->handle, buffer, (size_t)ulength); if (buffer == NULL)
Py_END_ALLOW_THREADS
return res < 0 ? res : ulength;
} else {
*newbuffer = PyMem_Malloc((size_t)ulength);
if (*newbuffer == NULL)
return MP_MEMORY_ERROR; return MP_MEMORY_ERROR;
Py_BEGIN_ALLOW_THREADS
res = _conn_recvall(conn->handle, *newbuffer, (size_t)ulength);
Py_END_ALLOW_THREADS
return res < 0 ? (Py_ssize_t)res : (Py_ssize_t)ulength;
} }
Py_BEGIN_ALLOW_THREADS
res = _conn_recvall(conn->handle, buffer, (size_t)ulength);
Py_END_ALLOW_THREADS
if (res >= 0) {
res = (Py_ssize_t)ulength;
} else if (*newbuffer != NULL) {
PyMem_Free(*newbuffer);
*newbuffer = NULL;
}
return res;
} }
/* /*
......
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