summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo RodolĂ  <g.rodola@gmail.com>2010-06-30 17:38:28 +0000
committerGiampaolo RodolĂ  <g.rodola@gmail.com>2010-06-30 17:38:28 +0000
commitf4082cac7a171becfc5f13daa210c52284283289 (patch)
tree3dad8a87e39c4d7c26ff1f0cef33d6b16b96f1ae
parent86b0dbe4768486762fb4dc5c829fb699204835e7 (diff)
downloadcpython-f4082cac7a171becfc5f13daa210c52284283289.tar.gz
fix issue #6589: cleanup asyncore.socket_map if smtpd.SMTPServer constructor raises an exception
-rwxr-xr-xLib/smtpd.py24
-rw-r--r--Misc/NEWS3
2 files changed, 18 insertions, 9 deletions
diff --git a/Lib/smtpd.py b/Lib/smtpd.py
index 3992d7bb4e..c3bd6a5add 100755
--- a/Lib/smtpd.py
+++ b/Lib/smtpd.py
@@ -274,15 +274,21 @@ class SMTPServer(asyncore.dispatcher):
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()
diff --git a/Misc/NEWS b/Misc/NEWS
index f93f5a9e7c..1625c0cd20 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -51,6 +51,9 @@ Build
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.