Skip to content

Commit 90aa92b

Browse files
author
TLS-Attacker Developer
committed
Fix resource leaks in ZipFileProvider
- Use try-with-resources to ensure ReadableByteChannel and FileOutputStream are properly closed - Use nested try-with-resources for FileOutputStream in unzipping section - Prevents potential resource leaks that could lead to file handle exhaustion
1 parent 47872ac commit 90aa92b

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
@@ -43,12 +43,10 @@ protected ZipFileProvider(
4343

4444
public List<String> getTargetList() {
4545
List<String> targetList;
46-
try {
47-
ReadableByteChannel readableByteChannel =
48-
Channels.newChannel(new URL(sourceUrl).openStream());
49-
FileOutputStream fileOutputStream = new FileOutputStream(zipFilename);
46+
try (ReadableByteChannel readableByteChannel =
47+
Channels.newChannel(new URL(sourceUrl).openStream());
48+
FileOutputStream fileOutputStream = new FileOutputStream(zipFilename)) {
5049
fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
51-
fileOutputStream.close();
5250
} catch (IOException e) {
5351
LOGGER.error("Could not download the current {} list with error ", listName, e);
5452
}
@@ -59,13 +57,13 @@ public List<String> getTargetList() {
5957
}
6058
File newFile = new File(outputFile);
6159
// write file content
62-
FileOutputStream fos = new FileOutputStream(newFile);
63-
int len;
64-
byte[] buffer = new byte[1024];
65-
while ((len = zis.read(buffer)) > 0) {
66-
fos.write(buffer, 0, len);
60+
try (FileOutputStream fos = new FileOutputStream(newFile)) {
61+
int len;
62+
byte[] buffer = new byte[1024];
63+
while ((len = zis.read(buffer)) > 0) {
64+
fos.write(buffer, 0, len);
65+
}
6766
}
68-
fos.close();
6967
} catch (IOException e) {
7068
LOGGER.error("Could not unzip the current {} list with error ", listName, e);
7169
}

0 commit comments

Comments
 (0)