Version v1.0.36
Merge: Ensure that we close input streams to not leak resources
CL: https://r8-review.googlesource.com/c/r8/+/25020
Bug: 112488773
Change-Id: I6093455da893192422df73864ee18909669b76d0
diff --git a/src/main/java/com/android/tools/r8/ExtractMarker.java b/src/main/java/com/android/tools/r8/ExtractMarker.java
index 272d2e5..dd9d98e 100644
--- a/src/main/java/com/android/tools/r8/ExtractMarker.java
+++ b/src/main/java/com/android/tools/r8/ExtractMarker.java
@@ -72,12 +72,14 @@
throws IOException, ResourceException {
if (FileUtils.isVDexFile(file)) {
PathOrigin vdexOrigin = new PathOrigin(file);
- VDexFile vdexFile = new VDexFile(vdexOrigin, Files.newInputStream(file));
- VDexFileReader reader = new VDexFileReader(vdexFile);
- int index = 0;
- for (byte[] bytes : reader.getDexFiles()) {
- appBuilder.addDexProgramData(bytes, new VdexOrigin(vdexOrigin, index));
- index++;
+ try (InputStream fileInputStream = Files.newInputStream(file)) {
+ VDexFile vdexFile = new VDexFile(vdexOrigin, fileInputStream);
+ VDexFileReader reader = new VDexFileReader(vdexFile);
+ int index = 0;
+ for (byte[] bytes : reader.getDexFiles()) {
+ appBuilder.addDexProgramData(bytes, new VdexOrigin(vdexOrigin, index));
+ index++;
+ }
}
} else {
appBuilder.addProgramFiles(file);
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index cd910e2..29aa201 100644
--- a/src/main/java/com/android/tools/r8/Version.java
+++ b/src/main/java/com/android/tools/r8/Version.java
@@ -11,7 +11,7 @@
// This field is accessed from release scripts using simple pattern matching.
// Therefore, changing this field could break our release scripts.
- public static final String LABEL = "v1.0.35";
+ public static final String LABEL = "v1.0.36";
private Version() {
}
diff --git a/src/main/java/com/android/tools/r8/dex/BaseFile.java b/src/main/java/com/android/tools/r8/dex/BaseFile.java
index 2f54fba..09a2028 100644
--- a/src/main/java/com/android/tools/r8/dex/BaseFile.java
+++ b/src/main/java/com/android/tools/r8/dex/BaseFile.java
@@ -8,7 +8,7 @@
import com.android.tools.r8.ResourceException;
import com.android.tools.r8.origin.Origin;
import com.android.tools.r8.utils.LebUtils;
-import com.google.common.io.ByteStreams;
+import com.android.tools.r8.utils.StreamUtils;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -17,7 +17,7 @@
protected final ByteBuffer buffer;
protected BaseFile(ProgramResource resource) throws ResourceException, IOException {
- this(resource.getOrigin(), ByteStreams.toByteArray(resource.getByteStream()));
+ this(resource.getOrigin(), StreamUtils.StreamToByteArrayClose(resource.getByteStream()));
}
protected BaseFile(Origin origin, byte[] bytes) {
diff --git a/src/main/java/com/android/tools/r8/utils/StreamUtils.java b/src/main/java/com/android/tools/r8/utils/StreamUtils.java
new file mode 100644
index 0000000..8d4ebc3
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/utils/StreamUtils.java
@@ -0,0 +1,20 @@
+// Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.utils;
+
+import com.google.common.io.ByteStreams;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class StreamUtils {
+ /**
+ * Read all data from the stream into a byte[], close the stream and return the bytes.
+ * @return The bytes of the stream
+ */
+ public static byte[] StreamToByteArrayClose(InputStream inputStream) throws IOException {
+ byte[] result = ByteStreams.toByteArray(inputStream);
+ inputStream.close();
+ return result;
+ }
+}