mirror of https://github.com/python/cpython
Only close sockets if they have been created. Reported by Blake Winton.
This commit is contained in:
parent
fb163784ab
commit
322c0d187d
|
@ -122,7 +122,8 @@ class FTP:
|
|||
self.sock = socket.socket(af, socktype, proto)
|
||||
self.sock.connect(sa)
|
||||
except socket.error, msg:
|
||||
self.sock.close()
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
continue
|
||||
break
|
||||
|
@ -272,13 +273,15 @@ class FTP:
|
|||
def makeport(self):
|
||||
'''Create a new socket and send a PORT command for it.'''
|
||||
msg = "getaddrinfo returns an empty list"
|
||||
sock = None
|
||||
for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
|
||||
af, socktype, proto, canonname, sa = res
|
||||
try:
|
||||
sock = socket.socket(af, socktype, proto)
|
||||
sock.bind(sa)
|
||||
except socket.error, msg:
|
||||
sock.close()
|
||||
if sock:
|
||||
sock.close()
|
||||
sock = None
|
||||
continue
|
||||
break
|
||||
|
|
|
@ -368,7 +368,8 @@ class HTTPConnection:
|
|||
except socket.error, msg:
|
||||
if self.debuglevel > 0:
|
||||
print 'connect fail:', (self.host, self.port)
|
||||
self.sock.close()
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
continue
|
||||
break
|
||||
|
|
|
@ -76,13 +76,15 @@ class POP3:
|
|||
self.host = host
|
||||
self.port = port
|
||||
msg = "getaddrinfo returns an empty list"
|
||||
self.sock = None
|
||||
for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
|
||||
af, socktype, proto, canonname, sa = res
|
||||
try:
|
||||
self.sock = socket.socket(af, socktype, proto)
|
||||
self.sock.connect(sa)
|
||||
except socket.error, msg:
|
||||
self.sock.close()
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
continue
|
||||
break
|
||||
|
|
|
@ -265,6 +265,7 @@ class SMTP:
|
|||
if not port: port = SMTP_PORT
|
||||
if self.debuglevel > 0: print 'connect:', (host, port)
|
||||
msg = "getaddrinfo returns an empty list"
|
||||
self.sock = None
|
||||
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
|
||||
af, socktype, proto, canonname, sa = res
|
||||
try:
|
||||
|
@ -273,7 +274,8 @@ class SMTP:
|
|||
self.sock.connect(sa)
|
||||
except socket.error, msg:
|
||||
if self.debuglevel > 0: print 'connect fail:', (host, port)
|
||||
self.sock.close()
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
continue
|
||||
break
|
||||
|
|
|
@ -210,7 +210,8 @@ class Telnet:
|
|||
self.sock = socket.socket(af, socktype, proto)
|
||||
self.sock.connect(sa)
|
||||
except socket.error, msg:
|
||||
self.sock.close()
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
continue
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue