Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d7554cf authored by John Reck's avatar John Reck
Browse files

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

This reverts commit b16411f8.

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

Test: make
Bug: 197500807
Change-Id: Id5118e2b21fa4b7a7198edfe9541f755fd581752
parent c0445999
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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;