summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2019-07-25 13:54:23 -0700
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-07-26 02:16:22 +0000
commit475ca92491fe525fec4442472c532d4bec4d69dd (patch)
treea98efe98de3d969ad6a4e7fe30c47ca93c7d1f6b
parentbc999ddb2d36dfcfdf57fd7e4ebebbe9217cd586 (diff)
downloadbase-475ca92491fe525fec4442472c532d4bec4d69dd.tar.gz
SharedMemory: clear file descriptor when explicitly closed.
We run the Cleaner in close, but after the fix in commit 6ca916a6, this no longer clears the value stored in the FileDescriptor, which means that subsequent operations on an explicitly closed SharedMemory will operate on a bogus fd number. Clearing the FileDescriptor value in close is sufficient, because Cleaner.clean is idempotent, and the only other case where it executes is when the FileDescriptor is phantom reachable, which means no one can access it to get its integer value. Bug: http://b/138392115 Bug: http://b/138323667 Test: treehugger Change-Id: I8bdb4c745466532a0712976416184c53fcf0dbf6 (cherry picked from commit a7641806ddf1099239632d53c629c062ff2168f4) (cherry picked from commit 20ab1e34273aa179053f5dc93e70c0191a39e91b)
-rw-r--r--core/java/android/os/SharedMemory.java3
1 files changed, 3 insertions, 0 deletions
diff --git a/core/java/android/os/SharedMemory.java b/core/java/android/os/SharedMemory.java
index 3e2ba3d3115f..0540e3611b52 100644
--- a/core/java/android/os/SharedMemory.java
+++ b/core/java/android/os/SharedMemory.java
@@ -259,6 +259,9 @@ public final class SharedMemory implements Parcelable, Closeable {
mCleaner.clean();
mCleaner = null;
}
+
+ // Cleaner.clean doesn't clear the value of the file descriptor.
+ mFileDescriptor.setInt$(-1);
}
@Override