diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-05-10 21:10:07 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-05-10 21:10:07 +0000 |
commit | f04a7690b53288c98c07e0aa05214cceebea1331 (patch) | |
tree | c8c22b100ff97ee5406e23b498db15918c36a973 /src/com/android/providers/downloads | |
parent | bf0c789f0c0aafba0f2ed468aee20f99ca9381ba (diff) | |
parent | 90e7485d68095b5fc5044dd1bc6cd4dfc485eaa3 (diff) | |
download | android_packages_providers_DownloadProvider-f04a7690b53288c98c07e0aa05214cceebea1331.tar.gz android_packages_providers_DownloadProvider-f04a7690b53288c98c07e0aa05214cceebea1331.tar.bz2 android_packages_providers_DownloadProvider-f04a7690b53288c98c07e0aa05214cceebea1331.zip |
am 90e7485d: am 02562d30: Merge "Avoid leaking cursors"
* commit '90e7485d68095b5fc5044dd1bc6cd4dfc485eaa3':
Avoid leaking cursors
Diffstat (limited to 'src/com/android/providers/downloads')
-rw-r--r-- | src/com/android/providers/downloads/DownloadProvider.java | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index 45af4456..48350f6a 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -1045,12 +1045,16 @@ public final class DownloadProvider extends ContentProvider { filteredValues = values; String filename = values.getAsString(Downloads.Impl._DATA); if (filename != null) { - Cursor c = query(uri, new String[] - { Downloads.Impl.COLUMN_TITLE }, null, null, null); - if (!c.moveToFirst() || c.getString(0).isEmpty()) { - values.put(Downloads.Impl.COLUMN_TITLE, new File(filename).getName()); + Cursor c = null; + try { + c = query(uri, new String[] + { Downloads.Impl.COLUMN_TITLE }, null, null, null); + if (!c.moveToFirst() || c.getString(0).isEmpty()) { + values.put(Downloads.Impl.COLUMN_TITLE, new File(filename).getName()); + } + } finally { + IoUtils.closeQuietly(c); } - c.close(); } Integer status = values.getAsInteger(Downloads.Impl.COLUMN_STATUS); @@ -1269,29 +1273,35 @@ public final class DownloadProvider extends ContentProvider { if (cursor == null) { Log.v(Constants.TAG, "null cursor in openFile"); } else { - if (!cursor.moveToFirst()) { - Log.v(Constants.TAG, "empty cursor in openFile"); - } else { - do { - Log.v(Constants.TAG, "row " + cursor.getInt(0) + " available"); - } while(cursor.moveToNext()); + try { + if (!cursor.moveToFirst()) { + Log.v(Constants.TAG, "empty cursor in openFile"); + } else { + do { + Log.v(Constants.TAG, "row " + cursor.getInt(0) + " available"); + } while(cursor.moveToNext()); + } + } finally { + cursor.close(); } - cursor.close(); } cursor = query(uri, new String[] { "_data" }, null, null, null); if (cursor == null) { Log.v(Constants.TAG, "null cursor in openFile"); } else { - if (!cursor.moveToFirst()) { - Log.v(Constants.TAG, "empty cursor in openFile"); - } else { - String filename = cursor.getString(0); - Log.v(Constants.TAG, "filename in openFile: " + filename); - if (new java.io.File(filename).isFile()) { - Log.v(Constants.TAG, "file exists in openFile"); + try { + if (!cursor.moveToFirst()) { + Log.v(Constants.TAG, "empty cursor in openFile"); + } else { + String filename = cursor.getString(0); + Log.v(Constants.TAG, "filename in openFile: " + filename); + if (new java.io.File(filename).isFile()) { + Log.v(Constants.TAG, "file exists in openFile"); + } } + } finally { + cursor.close(); } - cursor.close(); } } |