From bebc9585104fae9ef0c832c3ea33d9c913117ee6 Mon Sep 17 00:00:00 2001 From: demasterr Date: Sat, 9 Mar 2019 14:36:28 +0100 Subject: [PATCH] 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. --- android/src/com/mapswithme/util/log/ZipLogsTask.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/android/src/com/mapswithme/util/log/ZipLogsTask.java b/android/src/com/mapswithme/util/log/ZipLogsTask.java index bf78051e45..c607eb3c46 100644 --- a/android/src/com/mapswithme/util/log/ZipLogsTask.java +++ b/android/src/com/mapswithme/util/log/ZipLogsTask.java @@ -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) {