fix database cursor leak in GpxImportHelper.java

I moved the database cursor closing code outside the if block to fix the potential leak of empty database cursor (when moveToFirst() returns false).
This commit is contained in:
Yepang Liu 2016-10-09 11:47:10 +08:00 committed by GitHub
parent 2a146a14bb
commit 51222781f2

View file

@ -81,10 +81,12 @@ public class GpxImportHelper {
final Cursor returnCursor = application.getContentResolver().query(contentUri, null, null, null, null);
if (returnCursor != null && returnCursor.moveToFirst()) {
name = returnCursor.getString(returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
returnCursor.close();
} else {
name = null;
}
if (returnCursor != null && !returnCursor.isClosed()) {
returnCursor.close();
}
return name;
}