-
Notifications
You must be signed in to change notification settings - Fork 1.4k
resource leak: database cursor not closed #4591
Description
Dear developers,
I found several potential leaks of database cursor in your code.
(1) In the getLastRecordedVideoUri() method of MediaUtils class:
public static Uri getLastRecordedVideoUri(Activity activity) {
String[] proj = { MediaStore.Video.Media._ID };
Uri contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String sortOrder = MediaStore.Video.VideoColumns.DATE_TAKEN + " DESC";
CursorLoader loader = new CursorLoader(activity, contentUri, proj, null, null, sortOrder);
Cursor cursor = loader.loadInBackground();
cursor.moveToFirst();
return Uri.parse(contentUri.toString() + "/" + cursor.getLong(0));
}
The cursor is not closed.
(2) In the uploadImage() method of the PostUploadService class at line 530:
Cursor cur = mContext.getContentResolver().query(imageUri, projection, null, null, null);
cur is not closed
(3) In the uploadVideo() method of the PostUploadService class at line 677:
Cursor cur = mContext.getContentResolver().query(videoUri, projection, null, null, null);
cur is not closed
(4) In the getDefaultCategory() method of the SiteSettingsInterface class:
starting from line 154:
Cursor cursor = SiteSettingsTable.getCategory(id);
if (cursor != null && cursor.moveToFirst()) {
category.deserializeFromDatabase(cursor);
return category.name;
}
the cursor is not closed
(5) In the getPathFromContentUri() method of the EditPostActivity class:
starting from line 1525:
Cursor cur = getContentResolver().query(imageUri, projection, null, null, null);
if (cur != null && cur.moveToFirst()) {
int dataColumn = cur.getColumnIndex(MediaStore.Images.Media.DATA);
path = cur.getString(dataColumn);
cur.close();
}
return path;
If the cursor is empty (moveToFirst() will return false) the cursor will be left unclosed. In the above code, the cur.close() will only execute for non-empty cursors when moveToFirst() returns true.