Revert "Revert "SharedMemory: break Cleaner reference cycle.""

This reverts commit b16411f83a.

The original change was correct, and the revert re-introduced an
FD leak.

Test: make
Bug: 197500807
Change-Id: Id5118e2b21fa4b7a7198edfe9541f755fd581752
This commit is contained in:
John Reck
2021-09-20 14:42:43 -04:00
parent c044599920
commit 2d7554cfea

View File

@@ -63,7 +63,7 @@ public final class SharedMemory implements Parcelable, Closeable {
mMemoryRegistration = new MemoryRegistration(mSize);
mCleaner = Cleaner.create(mFileDescriptor,
new Closer(mFileDescriptor, mMemoryRegistration));
new Closer(mFileDescriptor.getInt$(), mMemoryRegistration));
}
/**
@@ -325,10 +325,10 @@ public final class SharedMemory implements Parcelable, Closeable {
* Cleaner that closes the FD
*/
private static final class Closer implements Runnable {
private FileDescriptor mFd;
private int mFd;
private MemoryRegistration mMemoryReference;
private Closer(FileDescriptor fd, MemoryRegistration memoryReference) {
private Closer(int fd, MemoryRegistration memoryReference) {
mFd = fd;
mMemoryReference = memoryReference;
}
@@ -336,7 +336,9 @@ public final class SharedMemory implements Parcelable, Closeable {
@Override
public void run() {
try {
Os.close(mFd);
FileDescriptor fd = new FileDescriptor();
fd.setInt$(mFd);
Os.close(fd);
} catch (ErrnoException e) { /* swallow error */ }
mMemoryReference.release();
mMemoryReference = null;