diff options
| author | 2010-05-14 13:50:04 -0700 | |
|---|---|---|
| committer | 2010-06-23 11:32:40 -0700 | |
| commit | 1ba38b600e181168c8897220048027a164c68b10 (patch) | |
| tree | 8cc765ed0dc98afcce450fcc00e1e94863d4110a | |
| parent | 03f0292744094ec107ffce71301c394503a31ded (diff) | |
Fix 2655246 file descriptor leak when accessing thumbnails
http://b/2655246
Moved from kraken to master (https://android-git.corp.google.com/g/#change,51691)
Change-Id: I7d0cffd745311d073415d597eb141e26fe1edcce
| -rw-r--r-- | core/java/android/provider/MediaStore.java | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java index 40ed980d6c66..9a3c6180bedb 100644 --- a/core/java/android/provider/MediaStore.java +++ b/core/java/android/provider/MediaStore.java @@ -317,22 +317,23 @@ public final class MediaStore { // Log.v(TAG, "getThumbnail: origId="+origId+", kind="+kind+", isVideo="+isVideo); // If the magic is non-zero, we simply return thumbnail if it does exist. // querying MediaProvider and simply return thumbnail. - MiniThumbFile thumbFile = MiniThumbFile.instance(baseUri); - long magic = thumbFile.getMagic(origId); - if (magic != 0) { - if (kind == MICRO_KIND) { - byte[] data = new byte[MiniThumbFile.BYTES_PER_MINTHUMB]; - if (thumbFile.getMiniThumbFromFile(origId, data) != null) { - bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); - if (bitmap == null) { - Log.w(TAG, "couldn't decode byte array."); + MiniThumbFile thumbFile = new MiniThumbFile(isVideo ? Video.Media.EXTERNAL_CONTENT_URI + : Images.Media.EXTERNAL_CONTENT_URI); + Cursor c = null; + try { + long magic = thumbFile.getMagic(origId); + if (magic != 0) { + if (kind == MICRO_KIND) { + byte[] data = new byte[MiniThumbFile.BYTES_PER_MINTHUMB]; + if (thumbFile.getMiniThumbFromFile(origId, data) != null) { + bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); + if (bitmap == null) { + Log.w(TAG, "couldn't decode byte array."); + } } - } - return bitmap; - } else if (kind == MINI_KIND) { - String column = isVideo ? "video_id=" : "image_id="; - Cursor c = null; - try { + return bitmap; + } else if (kind == MINI_KIND) { + String column = isVideo ? "video_id=" : "image_id="; c = cr.query(baseUri, PROJECTION, column + origId, null, null); if (c != null && c.moveToFirst()) { bitmap = getMiniThumbFromFile(c, baseUri, cr, options); @@ -340,17 +341,13 @@ public final class MediaStore { return bitmap; } } - } finally { - if (c != null) c.close(); } } - } - Cursor c = null; - try { Uri blockingUri = baseUri.buildUpon().appendQueryParameter("blocking", "1") .appendQueryParameter("orig_id", String.valueOf(origId)) .appendQueryParameter("group_id", String.valueOf(groupId)).build(); + if (c != null) c.close(); c = cr.query(blockingUri, PROJECTION, null, null, null); // This happens when original image/video doesn't exist. if (c == null) return null; @@ -397,6 +394,9 @@ public final class MediaStore { Log.w(TAG, ex); } finally { if (c != null) c.close(); + // To avoid file descriptor leak in application process. + thumbFile.deactivate(); + thumbFile = null; } return bitmap; } |