From e75f2b230a1188ebfeffcb7737dfe94bcc0f9e44 Mon Sep 17 00:00:00 2001 From: Albert Gorski Date: Sun, 9 Oct 2016 21:16:54 -0400 Subject: [PATCH] Ensure the ZipFile is closed in isZipFile() of ZipDexContainer When calling isZipFile() in ZipDexContainer, the ZipFile would remain open if the file was in fact a zip file but the ZipFile object would then go out of scope thus creating a resource leak. This ensures that the ZipFile is closed by adding a finally clause containing a close call at the end of the try catch block. --- .../org/jf/dexlib2/dexbacked/ZipDexContainer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/ZipDexContainer.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/ZipDexContainer.java index 97810e59..1b2d85d2 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/ZipDexContainer.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/ZipDexContainer.java @@ -123,13 +123,22 @@ public class ZipDexContainer implements MultiDexContainer { } public boolean isZipFile() { + ZipFile zipFile = null; try { - getZipFile(); + zipFile = getZipFile(); return true; } catch (IOException ex) { return false; } catch (NotAZipFileException ex) { return false; + } finally { + if(zipFile != null) { + try { + zipFile.close(); + } catch (IOException ex) { + // just eat it + } + } } }