Skip to content

Commit

Permalink
Close resource leak in Zip
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed May 15, 2017
1 parent 78e6851 commit a5a7bb0
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions java/client/src/org/openqa/selenium/io/Zip.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ private static void addToZip(String basePath, ZipOutputStream zos, File toAdd) t
}
}
} else {
FileInputStream fis = new FileInputStream(toAdd);
String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);
try (FileInputStream fis = new FileInputStream(toAdd)) {
String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);

ZipEntry entry = new ZipEntry(name.replace('\\', '/'));
zos.putNextEntry(entry);
ZipEntry entry = new ZipEntry(name.replace('\\', '/'));
zos.putNextEntry(entry);

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

fis.close();
zos.closeEntry();
int len;
byte[] buffer = new byte[4096];
while ((len = fis.read(buffer)) != -1) {
zos.write(buffer, 0, len);
}

zos.closeEntry();
}
}
}

Expand Down

0 comments on commit a5a7bb0

Please sign in to comment.