Browse Source

Merge pull request #12300 from nextcloud/fixCursorLeak

Use try-with-resources for Cursor in getUploadByRemotePath
Alper Öztürk 1 year ago
parent
commit
69d3136e61

+ 6 - 5
app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -347,16 +347,17 @@ public class UploadsStorageManager extends Observable {
 
     public OCUpload getUploadByRemotePath(String remotePath){
         OCUpload result = null;
-        Cursor cursor = getDB().query(
+        try (Cursor cursor = getDB().query(
             ProviderTableMeta.CONTENT_URI_UPLOADS,
             null,
             ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?",
             new String[]{remotePath},
-            ProviderTableMeta.UPLOADS_REMOTE_PATH+ " ASC");
+            ProviderTableMeta.UPLOADS_REMOTE_PATH + " ASC")) {
 
-        if (cursor != null) {
-            if (cursor.moveToFirst()) {
-                result = createOCUploadFromCursor(cursor);
+            if (cursor != null) {
+                if (cursor.moveToFirst()) {
+                    result = createOCUploadFromCursor(cursor);
+                }
             }
         }
         Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath);