]> granicus.if.org Git - python/commitdiff
Issue #8184: Fix a potential file descriptor leak when a
authorCharles-François Natali <neologix@free.fr>
Sat, 4 Feb 2012 14:12:08 +0000 (15:12 +0100)
committerCharles-François Natali <neologix@free.fr>
Sat, 4 Feb 2012 14:12:08 +0000 (15:12 +0100)
multiprocessing.Connection socket can't be bound.

Lib/multiprocessing/connection.py

index c6c61138341fed29b887d7f73341e0d8517feaa6..615f55dd229d740bfe8bce3ad113acf0a1d45ca0 100644 (file)
@@ -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