summaryrefslogtreecommitdiffstats
path: root/Lib/smtpd.py
diff options
context:
space:
mode:
authorGiampaolo RodolĂ  <g.rodola@gmail.com>2010-06-30 17:38:28 (GMT)
committerGiampaolo RodolĂ  <g.rodola@gmail.com>2010-06-30 17:38:28 (GMT)
commite00e2f008230c07e54c14f750c99fb755aa96dfc (patch)
treec41ec2a1a461ebe46580e21f6ddfcdbd2b51104b /Lib/smtpd.py
parent10947a6416b12f047ebe6890deeb1a3e6ce62a73 (diff)
downloadcpython-e00e2f008230c07e54c14f750c99fb755aa96dfc.zip
cpython-e00e2f008230c07e54c14f750c99fb755aa96dfc.tar.gz
cpython-e00e2f008230c07e54c14f750c99fb755aa96dfc.tar.bz2
fix issue #6589: cleanup asyncore.socket_map if smtpd.SMTPServer constructor raises an exception
Diffstat (limited to 'Lib/smtpd.py')
-rwxr-xr-xLib/smtpd.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/Lib/smtpd.py b/Lib/smtpd.py
index 3992d7b..c3bd6a5 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()