[Python-checkins] r82404 - in python/trunk: Lib/smtpd.py Misc/NEWS

giampaolo.rodola python-checkins at python.org
Wed Jun 30 19:38:29 CEST 2010


Author: giampaolo.rodola
Date: Wed Jun 30 19:38:28 2010
New Revision: 82404

Log:
fix issue #6589: cleanup asyncore.socket_map if smtpd.SMTPServer constructor raises an exception

Modified:
   python/trunk/Lib/smtpd.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/smtpd.py
==============================================================================
--- python/trunk/Lib/smtpd.py	(original)
+++ python/trunk/Lib/smtpd.py	Wed Jun 30 19:38:28 2010
@@ -274,15 +274,21 @@
         self._localaddr = localaddr
         self._remoteaddr = remoteaddr
         asyncore.dispatcher.__init__(self)
-        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
-        # try to re-use a server port if possible
-        self.set_reuse_addr()
-        self.bind(localaddr)
-        self.listen(5)
-        print >> DEBUGSTREAM, \
-              '%s started at %s\n\tLocal addr: %s\n\tRemote addr:%s' % (
-            self.__class__.__name__, time.ctime(time.time()),
-            localaddr, remoteaddr)
+        try:
+            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+            # try to re-use a server port if possible
+            self.set_reuse_addr()
+            self.bind(localaddr)
+            self.listen(5)
+        except:
+            # cleanup asyncore.socket_map before raising
+            self.close()
+            raise
+        else:
+            print >> DEBUGSTREAM, \
+                  '%s started at %s\n\tLocal addr: %s\n\tRemote addr:%s' % (
+                self.__class__.__name__, time.ctime(time.time()),
+                localaddr, remoteaddr)
 
     def handle_accept(self):
         conn, addr = self.accept()

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Jun 30 19:38:28 2010
@@ -51,6 +51,9 @@
 Library
 -------
 
+- Issue #6589: cleanup asyncore.socket_map in case smtpd.SMTPServer constructor 
+  raises an exception.
+
 - Issue #8959: fix regression caused by using unmodified libffi
   library on Windows.  ctypes does now again check the stack before
   and after calling foreign functions.


More information about the Python-checkins mailing list