Merge "Prevent file descriptor leak" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
013bc8ae8e
@@ -1395,6 +1395,9 @@ public class ExifInterface {
|
|||||||
}
|
}
|
||||||
mAssetInputStream = null;
|
mAssetInputStream = null;
|
||||||
mFilename = null;
|
mFilename = null;
|
||||||
|
// When FileDescriptor is duplicated and set to FileInputStream, ownership needs to be
|
||||||
|
// clarified in order for garbage collection to take place.
|
||||||
|
boolean isFdOwner = false;
|
||||||
if (isSeekableFD(fileDescriptor)) {
|
if (isSeekableFD(fileDescriptor)) {
|
||||||
mSeekableFileDescriptor = fileDescriptor;
|
mSeekableFileDescriptor = fileDescriptor;
|
||||||
// Keep the original file descriptor in order to save attributes when it's seekable.
|
// Keep the original file descriptor in order to save attributes when it's seekable.
|
||||||
@@ -1402,6 +1405,7 @@ public class ExifInterface {
|
|||||||
// feature won't be working.
|
// feature won't be working.
|
||||||
try {
|
try {
|
||||||
fileDescriptor = Os.dup(fileDescriptor);
|
fileDescriptor = Os.dup(fileDescriptor);
|
||||||
|
isFdOwner = true;
|
||||||
} catch (ErrnoException e) {
|
} catch (ErrnoException e) {
|
||||||
throw e.rethrowAsIOException();
|
throw e.rethrowAsIOException();
|
||||||
}
|
}
|
||||||
@@ -1411,7 +1415,7 @@ public class ExifInterface {
|
|||||||
mIsInputStream = false;
|
mIsInputStream = false;
|
||||||
FileInputStream in = null;
|
FileInputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = new FileInputStream(fileDescriptor);
|
in = new FileInputStream(fileDescriptor, isFdOwner);
|
||||||
loadAttributes(in);
|
loadAttributes(in);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtils.closeQuietly(in);
|
IoUtils.closeQuietly(in);
|
||||||
@@ -1966,7 +1970,7 @@ public class ExifInterface {
|
|||||||
} else if (mSeekableFileDescriptor != null) {
|
} else if (mSeekableFileDescriptor != null) {
|
||||||
FileDescriptor fileDescriptor = Os.dup(mSeekableFileDescriptor);
|
FileDescriptor fileDescriptor = Os.dup(mSeekableFileDescriptor);
|
||||||
Os.lseek(fileDescriptor, 0, OsConstants.SEEK_SET);
|
Os.lseek(fileDescriptor, 0, OsConstants.SEEK_SET);
|
||||||
in = new FileInputStream(fileDescriptor);
|
in = new FileInputStream(fileDescriptor, true);
|
||||||
}
|
}
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
// Should not be reached this.
|
// Should not be reached this.
|
||||||
|
|||||||
Reference in New Issue
Block a user