summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dongwon Kang <dwkang@google.com> 2012-01-05 16:49:25 +0900
committer Dongwon Kang <dwkang@google.com> 2012-01-05 17:17:48 +0900
commit399381868992c68abefa5dde62bfdc0a7e33e5e5 (patch)
tree2eb1dfa0326e401ba266c71f870631a94914e72c
parent9a03482c66b2f5c30c7fde38216239a1f233df02 (diff)
ThumbnailUtils: To fix misuse of FileInputStream.
We need to close it explicitly after using it. Without this, fd will be closed non-deterministically, and that will break the decode procedure. Bug: 5808889 Change-Id: Icf9ff9abd6e327b122c6916df9750016b3d1b616
-rw-r--r--media/java/android/media/ThumbnailUtils.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/media/java/android/media/ThumbnailUtils.java b/media/java/android/media/ThumbnailUtils.java
index b320515dfbac..8eb933247472 100644
--- a/media/java/android/media/ThumbnailUtils.java
+++ b/media/java/android/media/ThumbnailUtils.java
@@ -104,8 +104,10 @@ public class ThumbnailUtils {
}
if (bitmap == null) {
+ FileInputStream stream = null;
try {
- FileDescriptor fd = new FileInputStream(filePath).getFD();
+ stream = new FileInputStream(filePath);
+ FileDescriptor fd = stream.getFD();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inJustDecodeBounds = true;
@@ -125,7 +127,16 @@ public class ThumbnailUtils {
Log.e(TAG, "", ex);
} catch (OutOfMemoryError oom) {
Log.e(TAG, "Unable to decode file " + filePath + ". OutOfMemoryError.", oom);
+ } finally {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException ex) {
+ Log.e(TAG, "", ex);
+ }
}
+
}
if (kind == Images.Thumbnails.MICRO_KIND) {