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

Commit 487c11a3 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Fix provider leak in PFD

Code path to release content provider associated with the PFD was
inadvertently bypassed by a previous change. Reinstate that code
when closing the PFD.

Bug: 10767447
Change-Id: I23306cfb3c28c99e587892b17ca85efd3f7a8a07
parent 6df7d4a5
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2316,8 +2316,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();
        }
@@ -822,7 +838,11 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
    @Override
    public void writeToParcel(Parcel out, int flags) {
        if (mWrapped != null) {
            try {
                mWrapped.writeToParcel(out, flags);
            } finally {
                releaseResources();
            }
        } else {
            out.writeFileDescriptor(mFd);
            if (mCommFd != null) {
@@ -832,11 +852,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) {
                }
            }
        }
    }