diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-10-07 08:53:32 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-10-07 08:53:32 +0000 |
commit | 6b37360de0012a765b220e81a8f2f58f6b710c5f (patch) | |
tree | dad55b5f9cd26c224f4f62f580eaf78b9c8c397e /Lib/ftplib.py | |
parent | 3d4c935b919a7694e06742cc9cb974d22cb57233 (diff) | |
download | cpython-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.py | 7 |
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 |