From 87b6e4f729ac771a47da6004338f0f604e538c17 Mon Sep 17 00:00:00 2001 From: Matthew Zavislak Date: Thu, 3 Jan 2019 11:58:34 -0800 Subject: [PATCH] Fix resource leak (#53) - From StrictMode policy violation: ``` android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1786) at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:264) at java.util.zip.ZipFile.finalize(ZipFile.java:705) at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250) at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237) at java.lang.Daemons$Daemon.run(Daemons.java:103) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.Throwable: Explicit termination method 'close' not called at dalvik.system.CloseGuard.open(CloseGuard.java:221) at java.util.zip.ZipFile.(ZipFile.java:247) at java.util.zip.ZipFile.(ZipFile.java:152) at com.getkeepsafe.relinker.ApkLibraryInstaller.findAPKWithLibrary(ApkLibraryInstaller.java:71) at com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary(ApkLibraryInstaller.java:120) at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal(ReLinkerInstance.java:180) at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:136) at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:70) at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:51) ``` --- .../com/getkeepsafe/relinker/ApkLibraryInstaller.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java b/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java index 6f12fc9..150d944 100644 --- a/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java +++ b/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java @@ -59,9 +59,9 @@ public ZipFileInZipEntry(ZipFile zipFile, ZipEntry zipEntry) { } private ZipFileInZipEntry findAPKWithLibrary(final Context context, - final String[] abis, - final String mappedLibraryName, - final ReLinkerInstance instance) { + final String[] abis, + final String mappedLibraryName, + final ReLinkerInstance instance) { ZipFile zipFile = null; for (String sourceDir : sourceDirectories(context)) { @@ -96,6 +96,11 @@ private ZipFileInZipEntry findAPKWithLibrary(final Context context, } } } + + try { + zipFile.close(); + } catch (IOException ignored) { + } } return null;