From 83154e6d38c3db5f8f4665a4eb994cb1d689ce9b Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 28 Jul 2020 03:39:41 +0800 Subject: [PATCH] Check for active while locked --- mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt index 13efab19..38612767 100644 --- a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt +++ b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt @@ -198,13 +198,13 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U val result = input.readByte() Timber.i("Received callback #$index: $result") val callback = mutex.synchronized { - (callbackLookup[index] ?: error("Empty callback #$index")).also { + if (active) (callbackLookup[index] ?: error("Empty callback #$index")).also { if (it.shouldRemove(result)) { callbackLookup.remove(index) it.active = false } - } - } + } else null + } ?: break if (isDebugEnabled) Log.d(TAG, "Received callback #$index: $result") callback(input, result) }