diff options
| author | Josh Gao <jmgao@google.com> | 2019-07-26 13:42:58 -0700 |
|---|---|---|
| committer | Josh Gao <jmgao@google.com> | 2019-07-31 15:19:11 -0700 |
| commit | 75f730abaf0ff5c8139e79eabcc502a0e8f55d28 (patch) | |
| tree | 1ed551a1e21eaeeb8371a6d89d86aaa8b77e310b /core/java | |
| parent | 9fdb8f99107bddcc249999a1a1e2b7f22fc2b05b (diff) | |
SharedMemory: use fdsan to protect our fd.
Bug: http://b/138422309
Test: booted, saw the GraphicsStatsService fd misacquisition
Change-Id: I9350ec13e523e1bf86797a1231769d890f277008
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/os/SharedMemory.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/core/java/android/os/SharedMemory.java b/core/java/android/os/SharedMemory.java index 161a4b31f63e..2ba39827dab8 100644 --- a/core/java/android/os/SharedMemory.java +++ b/core/java/android/os/SharedMemory.java @@ -25,6 +25,8 @@ import android.system.OsConstants; import dalvik.system.VMRuntime; +import libcore.io.IoUtils; + import java.io.Closeable; import java.io.FileDescriptor; import java.nio.ByteBuffer; @@ -293,21 +295,24 @@ public final class SharedMemory implements Parcelable, Closeable { * Cleaner that closes the FD */ private static final class Closer implements Runnable { - private int mFd; + // This is a copy of the FileDescriptor we're attached to, in order to avoid a reference + // cycle. + private FileDescriptor mFd; private MemoryRegistration mMemoryReference; private Closer(int fd, MemoryRegistration memoryReference) { - mFd = fd; + mFd = new FileDescriptor(); + mFd.setInt$(fd); + IoUtils.setFdOwner(mFd, this); + mMemoryReference = memoryReference; } @Override public void run() { - try { - FileDescriptor fd = new FileDescriptor(); - fd.setInt$(mFd); - Os.close(fd); - } catch (ErrnoException e) { /* swallow error */ } + IoUtils.closeQuietly(mFd); + mFd = null; + mMemoryReference.release(); mMemoryReference = null; } |
