summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Josh Gao <jmgao@google.com> 2019-05-15 13:35:59 -0700
committer Josh Gao <jmgao@google.com> 2019-05-15 14:05:26 -0700
commit536cf5e016367ee8a48812c6cd047de047df36cf (patch)
tree1fabaaeb1819035c6260939211ef134adde1ad1e
parent28706f020b3bb4e93703e3405c03dc459fe1a04b (diff)
MemoryIntArray: dup in writeToParcel.
Previously, if a MemoryIntArray is written to a parcel from multiple threads, we'll create multiple ParcelFileDescriptors that own the same file descriptor, which fdsan doesn't like. Instead of adopting and then detaching, use ParcelFileDescriptor::fromFd which dups behind the scenes. Bug: http://b/132720476 Test: treehugger Change-Id: Iad4930cc2d8c59a9348fedb0889d24cb566afa62
-rw-r--r--core/java/android/util/MemoryIntArray.java10
1 files changed, 4 insertions, 6 deletions
diff --git a/core/java/android/util/MemoryIntArray.java b/core/java/android/util/MemoryIntArray.java
index 80b16075cdf6..7d287e38ba86 100644
--- a/core/java/android/util/MemoryIntArray.java
+++ b/core/java/android/util/MemoryIntArray.java
@@ -175,12 +175,10 @@ public final class MemoryIntArray implements Parcelable, Closeable {
@Override
public void writeToParcel(Parcel parcel, int flags) {
- ParcelFileDescriptor pfd = ParcelFileDescriptor.adoptFd(mFd);
- try {
- // Don't let writing to a parcel to close our fd - plz
- parcel.writeParcelable(pfd, flags & ~Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
- } finally {
- pfd.detachFd();
+ try (ParcelFileDescriptor pfd = ParcelFileDescriptor.fromFd(mFd)) {
+ parcel.writeParcelable(pfd, flags);
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
}
}