Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getExifOrientation does not close cursor on exception #216

Closed
consp1racy opened this issue May 19, 2016 · 1 comment
Closed

getExifOrientation does not close cursor on exception #216

consp1racy opened this issue May 19, 2016 · 1 comment

Comments

@consp1racy
Copy link

Move cursor declaration outside try block and close it when not null when exception is trown.

private int getExifOrientation(String sourceUri) {
    int exifOrientation = ORIENTATION_0;
    if (sourceUri.startsWith(ContentResolver.SCHEME_CONTENT)) {
        final String[] columns = { MediaStore.Images.Media.ORIENTATION };
        Cursor cursor = null;
        try {
            cursor = getContext().getContentResolver().query(Uri.parse(sourceUri), columns, null, null, null);
            // if (cursor != null) {
                if (cursor.moveToFirst()) {
                    int orientation = cursor.getInt(0);
                    if (VALID_ORIENTATIONS.contains(orientation) && orientation != ORIENTATION_USE_EXIF) {
                        exifOrientation = orientation;
                    } else {
                        Log.w(TAG, "Unsupported orientation: " + orientation);
                    }
                }
                cursor.close();
            // }
        } catch (Exception e) {
            Log.w(TAG, "Could not get orientation of image from media store");
            if (cursor != null) cursor.close();
        }
    } else if (sourceUri.startsWith(ImageSource.FILE_SCHEME) && !sourceUri.startsWith(ImageSource.ASSET_SCHEME)) {
        // ...
    }
    return exifOrientation;
}
@davemorrissey
Copy link
Owner

Thanks, that'll be fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants