Merge "Fix provider leak in PFD" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
840b3bd611
@@ -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;
|
||||
|
||||
@@ -564,7 +564,11 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (mWrapped != null) {
|
||||
mWrapped.close();
|
||||
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) {
|
||||
mWrapped.closeWithError(msg);
|
||||
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 {
|
||||
if (mClosed) return;
|
||||
mClosed = true;
|
||||
mGuard.close();
|
||||
// Status MUST be sent before closing actual descriptor
|
||||
writeCommStatusAndClose(status, msg);
|
||||
IoUtils.closeQuietly(mFd);
|
||||
}
|
||||
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) {
|
||||
mWrapped.writeToParcel(out, flags);
|
||||
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) {
|
||||
}
|
||||
// Not a real close, so emit no status
|
||||
closeWithStatus(Status.SILENCE, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user