Skip to content

resource leak: database cursor not closed #74

@andrew659

Description

@andrew659

Dear developers,

I found two potential leaks of database cursor in your code.

(1) In the method private void manageNewStoragePath(SQLiteDatabase db) of DatabaseHelper class at line 203 and 234:

https://github.com/nguillaumin/osmtracker-android/blob/master/app/src/main/java/me/guillaumin/android/osmtracker/db/DatabaseHelper.java

If the cursor is empty (no rows), it will not be closed as in the code only when moveToFirst() returns true (non-empty cursors), the cursor.close() statement at line 234 will execute.

(2) In the public static File getTrackDirFromDB(ContentResolver cr, long trackId) of DataHelper class at line 341:

https://github.com/nguillaumin/osmtracker-android/blob/master/app/src/main/java/me/guillaumin/android/osmtracker/db/DataHelper.java

if (c != null && c.getCount() != 0) {
            c.moveToFirst();
            @SuppressWarnings("deprecation")
            String trackPath = c.getString(c.getColumnIndex(Schema.COL_DIR));
            if (trackPath != null) {
                trackDir = new File(trackPath);
            }
            c.close();
            c = null;
        }

In the above code, if the cursor is empty (getCount() == 0), the cursor will be not closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions