summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2012-06-11 14:11:35 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2012-06-11 14:11:35 (GMT)
commit926f58df57dc201608b9e7d0e45a34a28fe49535 (patch)
treed049ad74fa1cd939d84d0aaa81d35c6a12d4e338 /Modules
parent0c2c692b8481efc0c4b35b9b422dafb5993c3b60 (diff)
downloadcpython-926f58df57dc201608b9e7d0e45a34a28fe49535.zip
cpython-926f58df57dc201608b9e7d0e45a34a28fe49535.tar.gz
cpython-926f58df57dc201608b9e7d0e45a34a28fe49535.tar.bz2
Issue #10133: Make multiprocessing deallocate buffer if socket read fails.
Patch by Hallvard B Furuseth.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_multiprocessing/socket_connection.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/Modules/_multiprocessing/socket_connection.c b/Modules/_multiprocessing/socket_connection.c
index 7ebf338..1169c0a 100644
--- a/Modules/_multiprocessing/socket_connection.c
+++ b/Modules/_multiprocessing/socket_connection.c
@@ -117,7 +117,7 @@ static Py_ssize_t
conn_recv_string(ConnectionObject *conn, char *buffer,
size_t buflength, char **newbuffer, size_t maxlength)
{
- int res;
+ Py_ssize_t res;
UINT32 ulength;
*newbuffer = NULL;
@@ -132,20 +132,23 @@ conn_recv_string(ConnectionObject *conn, char *buffer,
if (ulength > maxlength)
return MP_BAD_MESSAGE_LENGTH;
- if (ulength <= buflength) {
- Py_BEGIN_ALLOW_THREADS
- res = _conn_recvall(conn->handle, buffer, (size_t)ulength);
- Py_END_ALLOW_THREADS
- return res < 0 ? res : ulength;
- } else {
- *newbuffer = PyMem_Malloc((size_t)ulength);
- if (*newbuffer == NULL)
+ if (ulength > buflength) {
+ *newbuffer = buffer = PyMem_Malloc((size_t)ulength);
+ if (buffer == NULL)
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;
}
/*