Skip to content
Browse files

Fix resource leak: When call MediaMetadataRetriever.setDataSource or …

…getFrameAtTime should ensure call release in finally to avoid resource leak

                   Patch set 2: Remove unnecessary white spaces

Change-Id: I49a7f2fb99dc8b9560e7c17421125356e45a87ac
  • Loading branch information...
1 parent 7d0a8e3 commit 6e0d2a6e0ce70073f977844200f477b9c552a11e @YuanQY YuanQY committed with Gerrit Code Review
Showing with 14 additions and 4 deletions.
  1. +14 −4 media/java/android/media/videoeditor/VideoEditorImpl.java
View
18 media/java/android/media/videoeditor/VideoEditorImpl.java
@@ -1834,10 +1834,20 @@ private void generateProjectThumbnail() {
String filename = mI.getFilename();
if (mI instanceof MediaVideoItem) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
- retriever.setDataSource(filename);
- Bitmap bitmap = retriever.getFrameAtTime();
- retriever.release();
- retriever = null;
+ Bitmap bitmap = null;
+ try {
+ retriever.setDataSource(filename);
+ bitmap = retriever.getFrameAtTime();
+ } catch (RuntimeException ex) {
+ // Ignore failures while cleaning up.
+ } finally {
+ try {
+ retriever.release();
+ } catch (RuntimeException ex) {
+ // Ignore failures while cleaning up.
+ }
+ }
+
if (bitmap == null) {
String msg = "Thumbnail extraction from " +
filename + " failed";

0 comments on commit 6e0d2a6

Please sign in to comment.
Something went wrong with that request. Please try again.