Skip to content

Commit

Permalink
[ProviderModel] fix potential leaking cursor when no results found.
Browse files Browse the repository at this point in the history
  • Loading branch information
agrosner committed Feb 17, 2021
1 parent 928ed90 commit b763a77
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ abstract class BaseProviderModel : BaseModel(), ModelProvider {
orderBy: String?,
wrapper: DatabaseWrapper,
vararg columns: String?): T? {
val cursor = ContentUtils.query(FlowManager.contentResolver,
queryUri, whereOperatorGroup, orderBy, *columns)
if (cursor != null) {
ContentUtils.query(FlowManager.contentResolver,
queryUri, whereOperatorGroup, orderBy, *columns)?.use { cursor ->
if (cursor.moveToFirst()) {
val model: T = modelAdapter.loadFromCursor(cursor, wrapper) as T
cursor.close()
return model
return modelAdapter.loadFromCursor(cursor, wrapper) as T
}
}
return null
Expand Down

0 comments on commit b763a77

Please sign in to comment.