summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-11-11 17:21:14 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-11-11 17:21:14 +0000
commite431db0daa356d416a23d9a2e28bb71a2e3ae636 (patch)
tree7f1ac8f2cdc36eaff1eb2c5bda0d0af424117c07
parentec13cf214179704573ede688edac1297f9cdc1d3 (diff)
parent4ec824ad9b3102d2e4b65a1f84f3ac5366ac54e1 (diff)
Merge "Avoid using NIO channels in addAugmentedProtoToDropbox" into main
-rw-r--r--services/core/java/com/android/server/BootReceiver.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/BootReceiver.java b/services/core/java/com/android/server/BootReceiver.java
index 23cee9db2138..1588e0421675 100644
--- a/services/core/java/com/android/server/BootReceiver.java
+++ b/services/core/java/com/android/server/BootReceiver.java
@@ -53,6 +53,7 @@ import com.android.server.am.DropboxRateLimiter;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
@@ -400,9 +401,18 @@ public class BootReceiver extends BroadcastReceiver {
Slog.w(TAG, "Tombstone too large to add to DropBox: " + tombstone.toPath());
return;
}
- // Read the proto tombstone file as bytes.
- final byte[] tombstoneBytes = Files.readAllBytes(tombstone.toPath());
+ // Read the proto tombstone file as bytes.
+ // Previously used Files.readAllBytes() which internally creates a ThreadLocal BufferCache
+ // via ChannelInputStream that isn't properly released. Switched to
+ // FileInputStream.transferTo() which avoids the NIO channels completely,
+ // preventing the memory leak while maintaining the same functionality.
+ final byte[] tombstoneBytes;
+ try (FileInputStream fis = new FileInputStream(tombstone);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ fis.transferTo(baos);
+ tombstoneBytes = baos.toByteArray();
+ }
final File tombstoneProtoWithHeaders = File.createTempFile(
tombstone.getName(), ".tmp", TOMBSTONE_TMP_DIR);
Files.setPosixFilePermissions(