Skip to content

Commit e4815cc

Browse files
authored
Merge pull request #50 from tls-attacker/fix-resource-leaks
Fix resource leaks in ZipFileProvider
2 parents aa0619f + 35a6146 commit e4815cc

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/main/java/de/rub/nds/crawler/targetlist/ZipFileProvider.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ protected ZipFileProvider(
4444

4545
public List<String> getTargetList() {
4646
List<String> targetList;
47-
try {
48-
ReadableByteChannel readableByteChannel =
49-
Channels.newChannel(URL.of(URI.create(sourceUrl), null).openStream());
50-
FileOutputStream fileOutputStream = new FileOutputStream(zipFilename);
47+
try (ReadableByteChannel readableByteChannel =
48+
Channels.newChannel(URL.of(URI.create(sourceUrl), null).openStream());
49+
FileOutputStream fileOutputStream = new FileOutputStream(zipFilename)) {
5150
fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
52-
fileOutputStream.close();
5351
} catch (IOException e) {
5452
LOGGER.error("Could not download the current {} list with error ", listName, e);
5553
}
@@ -60,13 +58,13 @@ public List<String> getTargetList() {
6058
}
6159
File newFile = new File(outputFile);
6260
// write file content
63-
FileOutputStream fos = new FileOutputStream(newFile);
64-
int len;
65-
byte[] buffer = new byte[1024];
66-
while ((len = zis.read(buffer)) > 0) {
67-
fos.write(buffer, 0, len);
61+
try (FileOutputStream fos = new FileOutputStream(newFile)) {
62+
int len;
63+
byte[] buffer = new byte[1024];
64+
while ((len = zis.read(buffer)) > 0) {
65+
fos.write(buffer, 0, len);
66+
}
6867
}
69-
fos.close();
7068
} catch (IOException e) {
7169
LOGGER.error("Could not unzip the current {} list with error ", listName, e);
7270
}

0 commit comments

Comments
 (0)