Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

cpython (3.2): Issue #10133: Make multiprocessing deallocate buffer if socket read fails.

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

Jun 11, 2012, 7:19 AM

Post #1 of 1 (83 views)
Permalink
cpython (3.2): Issue #10133: Make multiprocessing deallocate buffer if socket read fails.

http://hg.python.org/cpython/rev/5643697070c0
changeset: 77409:5643697070c0
branch: 3.2
parent: 77380:02b4c62ce393
user: Richard Oudkerk <shibturn [at] gmail>
date: Mon Jun 11 15:12:12 2012 +0100
summary:
Issue #10133: Make multiprocessing deallocate buffer if socket read fails.

Patch by Hallvard B Furuseth.

files:
Misc/NEWS | 3 +
Modules/_multiprocessing/socket_connection.c | 29 +++++----
2 files changed, 19 insertions(+), 13 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -70,6 +70,9 @@
Library
-------

+- Issue #10133: Make multiprocessing deallocate buffer if socket read
+ fails. Patch by Hallvard B Furuseth.
+
- Issue #13854: Make multiprocessing properly handle non-integer
non-string argument to SystemExit.

diff --git a/Modules/_multiprocessing/socket_connection.c b/Modules/_multiprocessing/socket_connection.c
--- a/Modules/_multiprocessing/socket_connection.c
+++ b/Modules/_multiprocessing/socket_connection.c
@@ -117,7 +117,7 @@
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 @@
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;
}

/*

--
Repository URL: http://hg.python.org/cpython

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.