Skip to content

Commit 56b3f3f

Browse files
Merge pull request #306 from nextcloud/cursorFix
put cursor close in finally block to make sure no resource leak occurrs
2 parents 05a2583 + 2704a0d commit 56b3f3f

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/com/owncloud/android/providers/FileContentProvider.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,26 @@ private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs)
9898
case SINGLE_FILE:
9999
Cursor c = query(db, uri, null, where, whereArgs, null);
100100
String remoteId = "";
101-
if (c != null && c.moveToFirst()) {
102-
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
103-
//ThumbnailsCacheManager.removeFileFromCache(remoteId);
104-
c.close();
101+
try {
102+
if (c != null && c.moveToFirst()) {
103+
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
104+
//ThumbnailsCacheManager.removeFileFromCache(remoteId);
105+
}
106+
Log_OC.d(TAG, "Removing FILE " + remoteId);
107+
108+
count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
109+
ProviderTableMeta._ID
110+
+ "="
111+
+ uri.getPathSegments().get(1)
112+
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""),
113+
whereArgs);
114+
} catch (Exception e) {
115+
Log_OC.d(TAG, "DB-Error removing file!", e);
116+
} finally {
117+
if (c != null) {
118+
c.close();
119+
}
105120
}
106-
Log_OC.d(TAG, "Removing FILE " + remoteId);
107-
108-
count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
109-
ProviderTableMeta._ID
110-
+ "="
111-
+ uri.getPathSegments().get(1)
112-
+ (!TextUtils.isEmpty(where) ? " AND (" + where
113-
+ ")" : ""), whereArgs);
114121
break;
115122
case DIRECTORY:
116123
// deletion of folder is recursive

0 commit comments

Comments
 (0)