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

Commit 5ec679a0 authored by Xin Guan's avatar Xin Guan Committed by Ramanan Rajeswaran
Browse files

Fix crash in TranserPipe.

Sometimes the pipe has been closed when it's thread tries to access

E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: TransferPipe
E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileDescriptor android.os.ParcelFileDescriptor.getFileDescriptor()' on a null object reference
E AndroidRuntime: 	at com.android.internal.os.TransferPipe.run(TransferPipe.java:184)
E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:818)

Change-Id: I0fcd4a3334b49972903f2cb0edb51323ba3f49e5
parent c68f2762
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -174,15 +174,27 @@ public final class TransferPipe implements Runnable {
    }

    public void kill() {
        synchronized (this) {
            closeFd(0);
            closeFd(1);
        }
    }

    @Override
    public void run() {
        final byte[] buffer = new byte[1024];
        final FileInputStream fis = new FileInputStream(getReadFd().getFileDescriptor());
        final FileOutputStream fos = new FileOutputStream(mOutFd);
        final FileInputStream fis;
        final FileOutputStream fos;

        synchronized (this) {
            ParcelFileDescriptor readFd = getReadFd();
            if (readFd == null) {
                Slog.w(TAG, "Pipe has been closed...");
                return;
            }
            fis = new FileInputStream(readFd.getFileDescriptor());
            fos = new FileOutputStream(mOutFd);
        }

        if (DEBUG) Slog.i(TAG, "Ready to read pipe...");
        byte[] bufferPrefix = null;