Fixed possible memory leak ZipLogsTask

If an exception would be thrown, the streams would not be closed. The use-try-with-resources will close the resources. Therefore, the `out.close()` has also become unnecessary.
This commit is contained in:
demasterr 2019-03-09 14:36:28 +01:00 committed by Aleksandr Zatsepin
parent 7086d14316
commit bebc958510

View file

@ -55,11 +55,11 @@ class ZipLogsTask implements Runnable
private boolean zipFileAtPath(@NonNull String sourcePath, @NonNull String toLocation)
{
File sourceFile = new File(sourcePath);
try
try(FileOutputStream dest = new FileOutputStream(toLocation, false);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)))
{
BufferedInputStream origin;
FileOutputStream dest = new FileOutputStream(toLocation, false);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
if (sourceFile.isDirectory())
{
zipSubFolder(out, sourceFile, sourceFile.getParent().length());
@ -77,7 +77,6 @@ class ZipLogsTask implements Runnable
out.write(data, 0, count);
}
}
out.close();
}
catch (Exception e)
{