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

Commit dc7e0464 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android Git Automerger
Browse files

am a8b4da87: am 840b3bd6: Merge "Fix provider leak in PFD" into klp-dev

* commit 'a8b4da87':
  Fix provider leak in PFD
parents 7fed4c26 a8b4da87
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2440,8 +2440,7 @@ public abstract class ContentResolver {
        }

        @Override
        public void close() throws IOException {
            super.close();
        public void releaseResources() {
            if (!mProviderReleased) {
                ContentResolver.this.releaseProvider(mContentProvider);
                mProviderReleased = true;
+36 −19
Original line number Diff line number Diff line
@@ -564,7 +564,11 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
    @Override
    public void close() throws IOException {
        if (mWrapped != null) {
            try {
                mWrapped.close();
            } finally {
                releaseResources();
            }
        } else {
            closeWithStatus(Status.OK, null);
        }
@@ -579,7 +583,11 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
     */
    public void closeWithError(String msg) throws IOException {
        if (mWrapped != null) {
            try {
                mWrapped.closeWithError(msg);
            } finally {
                releaseResources();
            }
        } else {
            if (msg == null) {
                throw new IllegalArgumentException("Message must not be null");
@@ -588,17 +596,22 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
        }
    }

    private void closeWithStatus(int status, String msg) throws IOException {
        if (mWrapped != null) {
            mWrapped.closeWithStatus(status, msg);
        } else {
    private void closeWithStatus(int status, String msg) {
        if (mClosed) return;
        mClosed = true;
        mGuard.close();
        // Status MUST be sent before closing actual descriptor
        writeCommStatusAndClose(status, msg);
        IoUtils.closeQuietly(mFd);
        releaseResources();
    }

    /**
     * Called when the fd is being closed, for subclasses to release any other resources
     * associated with it, such as acquired providers.
     * @hide
     */
    public void releaseResources() {
    }

    private byte[] getOrCreateStatusBuffer() {
@@ -793,6 +806,9 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {

    @Override
    protected void finalize() throws Throwable {
        if (mWrapped != null) {
            releaseResources();
        }
        if (mGuard != null) {
            mGuard.warnIfOpen();
        }
@@ -824,7 +840,11 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
        // WARNING: This must stay in sync with Parcel::readParcelFileDescriptor()
        // in frameworks/native/libs/binder/Parcel.cpp
        if (mWrapped != null) {
            try {
                mWrapped.writeToParcel(out, flags);
            } finally {
                releaseResources();
            }
        } else {
            out.writeFileDescriptor(mFd);
            if (mCommFd != null) {
@@ -834,11 +854,8 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
                out.writeInt(0);
            }
            if ((flags & PARCELABLE_WRITE_RETURN_VALUE) != 0 && !mClosed) {
                try {
                // Not a real close, so emit no status
                closeWithStatus(Status.SILENCE, null);
                } catch (IOException e) {
                }
            }
        }
    }