Fix filedescriptor leakage in MediaMetadataRetriever

setDataSource(String) throws an IllegalArgumentException
when an IOException or FileNotFoundException occurs, but doesn't
close FileDescriptor accordingly.

Change-Id: Ib6e0f1418afeeb19e03abd4bedb4cc845a58b6b4
This commit is contained in:
harvey_tsai
2015-06-11 11:51:36 +08:00
committed by Narayan Kamath
parent a78c0e0b9a
commit e1856e4829

View File

@ -64,9 +64,7 @@ public class MediaMetadataRetriever
throw new IllegalArgumentException();
}
FileInputStream is = null;
try {
is = new FileInputStream(path);
try (FileInputStream is = new FileInputStream(path)) {
FileDescriptor fd = is.getFD();
setDataSource(fd, 0, 0x7ffffffffffffffL);
} catch (FileNotFoundException fileEx) {
@ -74,12 +72,6 @@ public class MediaMetadataRetriever
} catch (IOException ioEx) {
throw new IllegalArgumentException();
}
try {
if (is != null) {
is.close();
}
} catch (Exception e) {}
}
/**