summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-02-04 14:12:08 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-02-04 14:12:08 (GMT)
commitedc67feaa40765e9827a75f6304801d2373898bc (patch)
treef7214e0e8a7b13d95d1cde9f0bf8712e825343c8 /Lib
parentd85d0e724714d76c8ab8b42f5293313d1bd3784d (diff)
downloadcpython-edc67feaa40765e9827a75f6304801d2373898bc.zip
cpython-edc67feaa40765e9827a75f6304801d2373898bc.tar.gz
cpython-edc67feaa40765e9827a75f6304801d2373898bc.tar.bz2
Issue #8184: Fix a potential file descriptor leak when a
multiprocessing.Connection socket can't be bound.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/multiprocessing/connection.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
index c6c6113..615f55d 100644
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -575,10 +575,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 OSError:
+ self._socket.close()
+ raise
self._family = family
self._last_accepted = None