Skip to content

Commit a5a7bb0

Browse files
committed
Close resource leak in Zip
1 parent 78e6851 commit a5a7bb0

File tree

1 file changed

+12
-11
lines changed
  • java/client/src/org/openqa/selenium/io

1 file changed

+12
-11
lines changed

java/client/src/org/openqa/selenium/io/Zip.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,21 @@ private static void addToZip(String basePath, ZipOutputStream zos, File toAdd) t
5757
}
5858
}
5959
} else {
60-
FileInputStream fis = new FileInputStream(toAdd);
61-
String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);
60+
try (FileInputStream fis = new FileInputStream(toAdd)) {
61+
String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);
6262

63-
ZipEntry entry = new ZipEntry(name.replace('\\', '/'));
64-
zos.putNextEntry(entry);
63+
ZipEntry entry = new ZipEntry(name.replace('\\', '/'));
64+
zos.putNextEntry(entry);
6565

66-
int len;
67-
byte[] buffer = new byte[4096];
68-
while ((len = fis.read(buffer)) != -1) {
69-
zos.write(buffer, 0, len);
70-
}
7166

72-
fis.close();
73-
zos.closeEntry();
67+
int len;
68+
byte[] buffer = new byte[4096];
69+
while ((len = fis.read(buffer)) != -1) {
70+
zos.write(buffer, 0, len);
71+
}
72+
73+
zos.closeEntry();
74+
}
7475
}
7576
}
7677

0 commit comments

Comments
 (0)