summaryrefslogtreecommitdiff
path: root/Lib/ftplib.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-10-07 08:53:32 +0000
committerMartin v. Löwis <martin@v.loewis.de>2001-10-07 08:53:32 +0000
commit6b37360de0012a765b220e81a8f2f58f6b710c5f (patch)
treedad55b5f9cd26c224f4f62f580eaf78b9c8c397e /Lib/ftplib.py
parent3d4c935b919a7694e06742cc9cb974d22cb57233 (diff)
downloadcpython-6b37360de0012a765b220e81a8f2f58f6b710c5f.tar.gz
Only close sockets if they have been created. Reported by Blake Winton.
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r--Lib/ftplib.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 4aa6244c5e..4d5ac1abd1 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -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