From 2c265858d0b923a27300c40b4f2121b9fc744785 Mon Sep 17 00:00:00 2001 From: Paul Sliwowski Date: Mon, 20 May 2013 16:28:10 -0700 Subject: Fixed leak cursor in AlertReciever Bug: 8764753 This fixed cleans up the code and make sure we close the location cursor when finished with it. Change-Id: I815c2e99bedbfe52d81e95ea7efd546ec1343635 --- src/com/android/calendar/alerts/AlertReceiver.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/com') diff --git a/src/com/android/calendar/alerts/AlertReceiver.java b/src/com/android/calendar/alerts/AlertReceiver.java index e1f7dec6..da8e617e 100644 --- a/src/com/android/calendar/alerts/AlertReceiver.java +++ b/src/com/android/calendar/alerts/AlertReceiver.java @@ -764,23 +764,21 @@ public class AlertReceiver extends BroadcastReceiver { */ private static URLSpan[] getURLSpans(Context context, long eventId) { Cursor locationCursor = getLocationCursor(context, eventId); + + // Default to empty list + URLSpan[] urlSpans = new URLSpan[0]; if (locationCursor != null && locationCursor.moveToFirst()) { String location = locationCursor.getString(0); // Only one item in this cursor. - if (location == null || location.isEmpty()) { - // Return an empty list if we know there was nothing in the location field. - return new URLSpan[0]; + if (location != null && !location.isEmpty()) { + Spannable text = Utils.extendedLinkify(location, true); + // The linkify method should have found at least one link, at the very least. + // If no smart links were found, it should have set the whole string as a geo link. + urlSpans = text.getSpans(0, text.length(), URLSpan.class); } - - Spannable text = Utils.extendedLinkify(location, true); - - // The linkify method should have found at least one link, at the very least. - // If no smart links were found, it should have set the whole string as a geo link. - URLSpan[] urlSpans = text.getSpans(0, text.length(), URLSpan.class); - return urlSpans; + locationCursor.close(); } - // If no links were found or location was empty, return an empty list. - return new URLSpan[0]; + return urlSpans; } /** -- cgit v1.2.3