[Python-checkins] cpython (3.2): Issue #8184: Fix a potential file descriptor leak when a

charles-francois.natali python-checkins at python.org
Sat Feb 4 15:13:11 CET 2012


http://hg.python.org/cpython/rev/ba1e0a1ac5b7
changeset:   74759:ba1e0a1ac5b7
branch:      3.2
parent:      74752:e35f1c431302
user:        Charles-François Natali <neologix at free.fr>
date:        Sat Feb 04 14:55:53 2012 +0100
summary:
  Issue #8184: Fix a potential file descriptor leak when a
multiprocessing.Connection socket can't be bound.

files:
  Lib/multiprocessing/connection.py |  12 ++++++++----
  1 files changed, 8 insertions(+), 4 deletions(-)


diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -249,10 +249,14 @@
     '''
     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
 

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


More information about the Python-checkins mailing list