urllib.urequest: If error happens while parsing response headers, close socket.

Because otherwise, user doesn't get any response object, so cannot close
socket, and it leaks.
pull/208/head
Paul Sokolovsky 2017-09-12 08:43:38 +03:00
rodzic cad77291d5
commit b715ee0cb8
1 zmienionych plików z 34 dodań i 29 usunięć

Wyświetl plik

@ -22,7 +22,9 @@ def urlopen(url, data=None, method="GET"):
ai = usocket.getaddrinfo(host, port)
addr = ai[0][4]
s = usocket.socket()
try:
s.connect(addr)
if proto == "https:":
s = ussl.wrap_socket(s, server_hostname=host)
@ -56,5 +58,8 @@ def urlopen(url, data=None, method="GET"):
raise ValueError("Unsupported " + l)
elif l.startswith(b"Location:"):
raise NotImplementedError("Redirects not yet supported")
except OSError:
s.close()
raise
return s