Skip to content

Commit 3a9be78

Browse files
committed
Fix file handle leaks: infile never closed, output not closed on error
1 parent 581d11d commit 3a9be78

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/builder/downloadfile.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ def get_file(self, url, filename):
6969
try:
7070
msg = "Downloading file '{0}' to {1}".format(url, filename)
7171
logging.info(msg)
72-
73-
infile = self.urlopen_with_retry(url)
74-
output = open(filename, "wb")
75-
output.write(infile.read())
76-
output.close()
72+
with self.urlopen_with_retry(url) as infile:
73+
with open(filename, "wb") as output:
74+
output.write(infile.read())
7775
except Exception:
7876
msg = "Error downloading file '{0}' to {1}".format(url, filename)
7977
logging.error(msg)

0 commit comments

Comments
 (0)