Bug 888053 - Fix for Cursor leak in TopSitesView.java. r=bnicholson
authorChris Kitching <ckitching@mozilla.com>
Tue, 02 Jul 2013 15:49:07 -0400
changeset 137235 982d07833360c264e90d4a6e34f8b7d31bb2620c
parent 137234 c361c2af8910f187eee8714981e2aed99bca9e7c
child 137236 c94fdeb1fa666619c7bf63cc7b743dc791aa39fe
push id1824
push userryanvm@gmail.com
push dateWed, 03 Jul 2013 18:16:56 +0000
treeherderfx-team@dcbbfcdf7bb4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs888053
milestone25.0a1
Bug 888053 - Fix for Cursor leak in TopSitesView.java. r=bnicholson
mobile/android/base/widget/TopSitesView.java
--- a/mobile/android/base/widget/TopSitesView.java
+++ b/mobile/android/base/widget/TopSitesView.java
@@ -645,27 +645,33 @@ public class TopSitesView extends GridVi
                     @Override
                     public Bitmap doInBackground(Void... params) {
                         final ContentResolver resolver = mContext.getContentResolver();
                         BrowserDB.pinSite(resolver, holder.getUrl(), holder.getTitle(), position);
 
                         List<String> urls = new ArrayList<String>();
                         urls.add(holder.getUrl());
 
-                        Cursor c = BrowserDB.getThumbnailsForUrls(resolver, urls);
-                        if (c == null || !c.moveToFirst()) {
-                            return null;
-                        }
+                        Bitmap bitmap = null;
+                        Cursor c = null;
+
+                        try {
+                            c = BrowserDB.getThumbnailsForUrls(resolver, urls);
+                            if (c != null && c.moveToFirst()) {
+                                final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Thumbnails.DATA));
 
-                        final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Thumbnails.DATA));
-                        Bitmap bitmap = null;
-                        if (b != null && b.length > 0) {
-                            bitmap = BitmapUtils.decodeByteArray(b);
+                                if (b != null && b.length > 0) {
+                                    bitmap = BitmapUtils.decodeByteArray(b);
+                                }
+                            }
+                        } finally {
+                            if (c != null) {
+                                c.close();
+                            }
                         }
-                        c.close();
 
                         return bitmap;
                     }
 
                     @Override
                     public void onPostExecute(Bitmap b) {
                         displayThumbnail(v, b);
                     }