From 2273a12b2414f33eac367960c60be2b44d2dc887 Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Fri, 6 Dec 2024 17:20:38 +0300 Subject: [PATCH] CpuInfoProvider.cpuinfo(): fix resource leak (strict mode violation) This commit also addresses the issue https://github.com/fingerprintjs/fingerprintjs-android/issues/118 --- .../fingerprint/info_providers/CpuInfoProvider.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/CpuInfoProvider.kt b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/CpuInfoProvider.kt index abde100..9518d77 100644 --- a/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/CpuInfoProvider.kt +++ b/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/info_providers/CpuInfoProvider.kt @@ -59,11 +59,12 @@ internal class CpuInfoProviderImpl : private fun getCpuInfo(): Map { val map: MutableMap = 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