diff options
author | Charles-François Natali <neologix@free.fr> | 2012-02-04 13:55:53 (GMT) |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2012-02-04 13:55:53 (GMT) |
commit | 992ca5278ec1d7529c4aeedfed74051890feac1b (patch) | |
tree | 7e555dd40f487dbd2a990682d5d562a31debb4fd | |
parent | 90b13583bcbed14e92c4ad880057ec48017e5a33 (diff) | |
download | cpython-992ca5278ec1d7529c4aeedfed74051890feac1b.zip cpython-992ca5278ec1d7529c4aeedfed74051890feac1b.tar.gz cpython-992ca5278ec1d7529c4aeedfed74051890feac1b.tar.bz2 |
Issue #8184: Fix a potential file descriptor leak when a
multiprocessing.Connection socket can't be bound.
-rw-r--r-- | Lib/multiprocessing/connection.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index d6c23fb..df00f1d 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -249,10 +249,14 @@ class SocketListener(object): ''' def __init__(self, address, family, backlog=1): self._socket = socket.socket(getattr(socket, family)) - self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self._socket.bind(address) - self._socket.listen(backlog) - self._address = self._socket.getsockname() + try: + self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self._socket.bind(address) + self._socket.listen(backlog) + self._address = self._socket.getsockname() + except socket.error: + self._socket.close() + raise self._family = family self._last_accepted = None |