Skip to content
Snippets Groups Projects
Commit 8790877c authored by Lennart Goedhart's avatar Lennart Goedhart
Browse files

Properly close DB handles so that we don't leak them.

parent dd71fc55
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,7 @@ public class CNLConfigDbHelper extends SQLiteOpenHelper {
insertValues.put(CNLConfigContract.ConfigEntry.COLUMN_NAME_KEY, "");
insertValues.put(CNLConfigContract.ConfigEntry.COLUMN_NAME_LAST_RADIO_CHANNEL, 0x14 );
configDb.insertWithOnConflict(CNLConfigContract.ConfigEntry.TABLE_NAME, null, insertValues, SQLiteDatabase.CONFLICT_IGNORE);
configDb.close();
}
public String getHmac( String stickSerial ){
......@@ -67,14 +68,16 @@ public class CNLConfigDbHelper extends SQLiteOpenHelper {
new String[] { CNLConfigContract.ConfigEntry.COLUMN_NAME_HMAC },
CNLConfigContract.ConfigEntry.COLUMN_NAME_STICK_SERIAL + " = ?", new String[]{ stickSerial }, null, null, null);
String hmac = null;
if (cursor != null && cursor.moveToFirst()) {
String hmac = cursor.getString(cursor.getColumnIndex(CNLConfigContract.ConfigEntry.COLUMN_NAME_HMAC));
hmac = cursor.getString(cursor.getColumnIndex(CNLConfigContract.ConfigEntry.COLUMN_NAME_HMAC));
cursor.close();
return hmac;
} else {
return null;
}
configDb.close();
return hmac;
}
public String getKey( String stickSerial ){
......@@ -84,14 +87,16 @@ public class CNLConfigDbHelper extends SQLiteOpenHelper {
new String[] { CNLConfigContract.ConfigEntry.COLUMN_NAME_KEY },
CNLConfigContract.ConfigEntry.COLUMN_NAME_STICK_SERIAL + " = ?", new String[]{ stickSerial }, null, null, null);
String key = null;
if (cursor != null && cursor.moveToFirst()) {
String hmac = cursor.getString(cursor.getColumnIndex(CNLConfigContract.ConfigEntry.COLUMN_NAME_KEY));
key = cursor.getString(cursor.getColumnIndex(CNLConfigContract.ConfigEntry.COLUMN_NAME_KEY));
cursor.close();
return hmac;
} else {
return null;
}
configDb.close();
return key;
}
public int setHmacAndKey( String stickSerial, String hmac, String key ) {
......@@ -112,6 +117,7 @@ public class CNLConfigDbHelper extends SQLiteOpenHelper {
whereArgs
);
configDb.close();
return affectedRows;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment