Skip to content

Commit fc7ce78

Browse files
committed
#128 Close inputstream after decoding bitmap
1 parent 7d42d6c commit fc7ce78

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

library/src/com/davemorrissey/labs/subscaleview/decoder/SkiaImageDecoder.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.net.Uri;
1010
import android.text.TextUtils;
1111

12+
import java.io.InputStream;
1213
import java.util.List;
1314

1415
/**
@@ -59,8 +60,16 @@ public Bitmap decode(Context context, Uri uri) throws Exception {
5960
} else if (uriString.startsWith(FILE_PREFIX)) {
6061
bitmap = BitmapFactory.decodeFile(uriString.substring(FILE_PREFIX.length()), options);
6162
} else {
62-
ContentResolver contentResolver = context.getContentResolver();
63-
bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(uri), null, options);
63+
InputStream inputStream = null;
64+
try {
65+
ContentResolver contentResolver = context.getContentResolver();
66+
inputStream = contentResolver.openInputStream(uri);
67+
bitmap = BitmapFactory.decodeStream(inputStream, null, options);
68+
} finally {
69+
if (inputStream != null) {
70+
try { inputStream.close(); } catch (Exception e) { }
71+
}
72+
}
6473
}
6574
if (bitmap == null) {
6675
throw new RuntimeException("Skia image region decoder returned null bitmap - image format may not be supported");

0 commit comments

Comments
 (0)