Skip to content

Commit

Permalink
chore: add mutex for error list
Browse files Browse the repository at this point in the history
  • Loading branch information
cinit committed Oct 2, 2023
1 parent e1b4ffe commit b2cffb4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/src/main/java/io/github/qauxv/hook/BaseFunctionHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ abstract class BaseFunctionHook(
) : ITraceableDynamicHook, IUiItemAgentProvider {

private val mErrors: ArrayList<Throwable> = ArrayList()
private val mErrorsLock: Any = Any()
private var mInitialized = false
private var mInitializeResult = false
private val mHookKey: String = hookKey ?: this::class.java.simpleName
Expand Down Expand Up @@ -113,13 +114,15 @@ abstract class BaseFunctionHook(
override fun traceError(e: Throwable) {
// check if there is already an error with the same error message and stack trace
var alreadyLogged = false
for (error in mErrors) {
if (error.message == e.message && Arrays.equals(error.stackTrace, e.stackTrace)) {
alreadyLogged = true
synchronized(mErrorsLock) {
for (error in mErrors) {
if (error.message == e.message && Arrays.equals(error.stackTrace, e.stackTrace)) {
alreadyLogged = true
}
}
if (!alreadyLogged) {
mErrors.add(e)
}
}
if (!alreadyLogged) {
mErrors.add(e)
}
Log.e(e)
}
Expand Down

0 comments on commit b2cffb4

Please sign in to comment.