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

Commit 18668392 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Maybe fix #2422586: Native crash in android_os_Parcel_closeFileDescriptor()

killed the phone process

Try to make sure we never have a ParcelFileDescriptor with a null
FileDescriptor.  That is just wrong.

Change-Id: Ib779ad1852dd239827797cd8f93505bfe6157e58
parent d0f11ea9
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -273,7 +273,8 @@ public class MemoryFile
     * @hide
     * @hide
     */
     */
    public ParcelFileDescriptor getParcelFileDescriptor() throws IOException {
    public ParcelFileDescriptor getParcelFileDescriptor() throws IOException {
        return new ParcelFileDescriptor(getFileDescriptor());
        FileDescriptor fd = getFileDescriptor();
        return fd != null ? new ParcelFileDescriptor(fd) : null;
    }
    }


    /**
    /**
+9 −3
Original line number Original line Diff line number Diff line
@@ -113,7 +113,7 @@ public class ParcelFileDescriptor implements Parcelable {
        }
        }
        
        
        FileDescriptor fd = Parcel.openFileDescriptor(path, mode);
        FileDescriptor fd = Parcel.openFileDescriptor(path, mode);
        return new ParcelFileDescriptor(fd);
        return fd != null ? new ParcelFileDescriptor(fd) : null;
    }
    }


    /**
    /**
@@ -127,7 +127,7 @@ public class ParcelFileDescriptor implements Parcelable {
     */
     */
    public static ParcelFileDescriptor fromSocket(Socket socket) {
    public static ParcelFileDescriptor fromSocket(Socket socket) {
        FileDescriptor fd = getFileDescriptorFromSocket(socket);
        FileDescriptor fd = getFileDescriptorFromSocket(socket);
        return new ParcelFileDescriptor(fd);
        return fd != null ? new ParcelFileDescriptor(fd) : null;
    }
    }


    // Extracts the file descriptor from the specified socket and returns it untouched
    // Extracts the file descriptor from the specified socket and returns it untouched
@@ -163,7 +163,10 @@ public class ParcelFileDescriptor implements Parcelable {
     *             If an error occurs attempting to close this ParcelFileDescriptor.
     *             If an error occurs attempting to close this ParcelFileDescriptor.
     */
     */
    public void close() throws IOException {
    public void close() throws IOException {
        synchronized (this) {
            if (mClosed) return;
            mClosed = true;
            mClosed = true;
        }
        if (mParcelDescriptor != null) {
        if (mParcelDescriptor != null) {
            // If this is a proxy to another file descriptor, just call through to its
            // If this is a proxy to another file descriptor, just call through to its
            // close method.
            // close method.
@@ -235,6 +238,9 @@ public class ParcelFileDescriptor implements Parcelable {
    
    
    /*package */ParcelFileDescriptor(FileDescriptor descriptor) {
    /*package */ParcelFileDescriptor(FileDescriptor descriptor) {
        super();
        super();
        if (descriptor == null) {
            throw new NullPointerException("descriptor must not be null");
        }
        mFileDescriptor = descriptor;
        mFileDescriptor = descriptor;
        mParcelDescriptor = null;
        mParcelDescriptor = null;
    }
    }