Skip to content

Commit

Permalink
CpuInfoProvider.cpuinfo(): fix resource leak (strict mode violation)
Browse files Browse the repository at this point in the history
This commit also addresses the issue #118
  • Loading branch information
Sergey-Makarov committed Dec 9, 2024
1 parent 694a50b commit 8278d1a
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ internal class CpuInfoProviderImpl :

private fun getCpuInfo(): Map<String, String> {
val map: MutableMap<String, String> = HashMap()
val s = Scanner(File(CPU_INFO_PATH))
while (s.hasNextLine()) {
val cpuInfoValues = s.nextLine()!!.split(KEY_VALUE_DELIMITER)
if (cpuInfoValues.size > 1) map[cpuInfoValues[0].trim { it <= ' ' }] =
cpuInfoValues[1].trim { it <= ' ' }
Scanner(File(CPU_INFO_PATH)).use { s ->
while (s.hasNextLine()) {
val cpuInfoValues = s.nextLine()!!.split(KEY_VALUE_DELIMITER)
if (cpuInfoValues.size > 1) map[cpuInfoValues[0].trim { it <= ' ' }] =
cpuInfoValues[1].trim { it <= ' ' }
}
}

return map
Expand Down

0 comments on commit 8278d1a

Please sign in to comment.