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

Commit a0c949d5 authored by Josh Gao's avatar Josh Gao Committed by Gerrit Code Review
Browse files

Merge changes I9350ec13,I809d9191,I235f727d,I1930f3ba

* changes:
  SharedMemory: use fdsan to protect our fd.
  Revert "Revert "SharedMemory: break Cleaner reference cycle.""
  Revert "SharedMemory: break Cleaner reference cycle." Bug: 138422309
  GraphicsStatService: fix double close.
parents 94d801a5 75f730ab
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -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;
        }
+1 −1
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ public class GraphicsStatsService extends IGraphicsStats.Stub {
            if (!file.getFileDescriptor().valid()) {
                throw new IllegalStateException("Invalid file descriptor");
            }
            return new ParcelFileDescriptor(file.getFileDescriptor());
            return ParcelFileDescriptor.dup(file.getFileDescriptor());
        } catch (IOException ex) {
            throw new IllegalStateException("Failed to get PFD from memory file", ex);
        }