mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	fix issue #6589: cleanup asyncore.socket_map if smtpd.SMTPServer constructor raises an exception
This commit is contained in:
		
							parent
							
								
									10947a6416
								
							
						
					
					
						commit
						e00e2f0082
					
				
					 2 changed files with 18 additions and 9 deletions
				
			
		
							
								
								
									
										24
									
								
								Lib/smtpd.py
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								Lib/smtpd.py
									
										
									
									
									
								
							|  | @ -274,15 +274,21 @@ def __init__(self, localaddr, remoteaddr): | |||
|         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() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Giampaolo Rodolà
						Giampaolo Rodolà