[core] Fix resource leak (#813)
This commit is contained in:
parent
bfe31837ad
commit
521786f6af
|
|
@ -14,16 +14,16 @@ import java.util.zip.ZipEntry;
|
|||
|
||||
import sun.net.www.ParseUtil;
|
||||
|
||||
public final class ClassPathURLStreamHandler extends Handler {
|
||||
final class ClassPathURLStreamHandler extends Handler {
|
||||
private final String fileUri;
|
||||
private final JarFile jarFile;
|
||||
|
||||
public ClassPathURLStreamHandler(String jarFileName) throws IOException {
|
||||
ClassPathURLStreamHandler(String jarFileName) throws IOException {
|
||||
jarFile = new JarFile(jarFileName);
|
||||
fileUri = new File(jarFileName).toURI().toString();
|
||||
}
|
||||
|
||||
public URL getEntryUrlOrNull(String entryName) {
|
||||
URL getEntryUrlOrNull(String entryName) {
|
||||
if (jarFile.getEntry(entryName) != null) {
|
||||
try {
|
||||
String encodedName = ParseUtil.encodePath(entryName, false);
|
||||
|
|
@ -40,7 +40,12 @@ public final class ClassPathURLStreamHandler extends Handler {
|
|||
return new ClassPathURLConnection(url);
|
||||
}
|
||||
|
||||
private class ClassPathURLConnection extends JarURLConnection {
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
private final class ClassPathURLConnection extends JarURLConnection {
|
||||
private JarFile connectionJarFile = null;
|
||||
private ZipEntry jarEntry = null;
|
||||
private InputStream jarInput = null;
|
||||
|
|
@ -48,6 +53,12 @@ public final class ClassPathURLStreamHandler extends Handler {
|
|||
|
||||
private ClassPathURLConnection(URL url) throws MalformedURLException {
|
||||
super(url);
|
||||
setUseCaches(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseCaches(boolean usecaches) {
|
||||
super.setUseCaches(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.system.Os;
|
|||
import android.system.OsConstants;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -16,6 +17,7 @@ import java.net.URL;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
|
@ -164,6 +166,15 @@ public final class InMemoryDelegateLastClassLoader extends ByteBufferDexClassLoa
|
|||
return new CompoundEnumeration<>(resources);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LspModuleClassLoader[" +
|
||||
"module=" + apk + "," +
|
||||
"nativeLibraryDirs=" + Arrays.toString(nativeLibraryDirs.toArray()) + "," +
|
||||
super.toString() + "]";
|
||||
}
|
||||
|
||||
public static InMemoryDelegateLastClassLoader loadApk(File apk,
|
||||
String librarySearchPath,
|
||||
ClassLoader parent) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue