Merge "Maybe fix #2422586: Native crash in android_os_Parcel_closeFileDescriptor() killed the phone process"

This commit is contained in:
Dianne Hackborn
2010-03-24 12:10:31 -07:00
committed by Android (Google) Code Review
2 changed files with 11 additions and 4 deletions

View File

@@ -273,7 +273,8 @@ public class MemoryFile
* @hide
*/
public ParcelFileDescriptor getParcelFileDescriptor() throws IOException {
return new ParcelFileDescriptor(getFileDescriptor());
FileDescriptor fd = getFileDescriptor();
return fd != null ? new ParcelFileDescriptor(fd) : null;
}
/**

View File

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