diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-05-08 15:56:32 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-05-08 15:57:38 +0200 |
commit | cbc3988628d09ed8a4fe967e1f21786f46cb038b (patch) | |
tree | fc297d384d6b9bbd33ea27b8252428dde2763623 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper | |
parent | 79117b1ef8074434579191e1dd734f9445d6544f (diff) | |
download | open-keychain-cbc3988628d09ed8a4fe967e1f21786f46cb038b.tar.gz open-keychain-cbc3988628d09ed8a4fe967e1f21786f46cb038b.tar.bz2 open-keychain-cbc3988628d09ed8a4fe967e1f21786f46cb038b.zip |
proper null checks and closing of cursors everywhere
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java index f22fcd4b8..d7d73cf3d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/FileHelper.java @@ -112,16 +112,18 @@ public class FileHelper { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = {"_data"}; - Cursor cursor = null; - + Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); try { - cursor = context.getContentResolver().query(uri, projection, null, null, null); - int columnIndex = cursor.getColumnIndexOrThrow("_data"); - if (cursor.moveToFirst()) { + if (cursor != null && cursor.moveToFirst()) { + int columnIndex = cursor.getColumnIndexOrThrow("_data"); return cursor.getString(columnIndex); } } catch (Exception e) { // Eat it + } finally { + if (cursor != null) { + cursor.close(); + } } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); |