lshal: do not pthread_kill
All of the commands are executed by starting a thread,
and if there is a timeout, sending a SIGINT to the thread,
which invokes pthread_exit from the signal handler. If
pthread_exit is called while the thread is in jemalloc code,
that might cause problems.
To avoid this, we stop calling pthread_kill on the background
helper threads. If they time out, simply ignore the thread and
move on. Although this causes memory leak, the lshal tool is
a debugging tool that is intended to run for a short period of
time, not as a daemon. So this is okay.
Test: lshal_test
Bug: 311143089
Change-Id: I031e5fb6cfc0f10952d10e41d6d1f716ff51dcb3
diff --git a/cmds/lshal/Timeout.h b/cmds/lshal/Timeout.h
index e8d22d9..012a5d5 100644
--- a/cmds/lshal/Timeout.h
+++ b/cmds/lshal/Timeout.h
@@ -72,10 +72,14 @@
return false;
}
bool success = state.wait(now + delay);
- if (!success) {
- pthread_kill(thread, SIGINT);
+ if (success) {
+ pthread_join(thread, nullptr);
+ } else {
+ // b/311143089: Abandon this background thread. Resources for a detached
+ // thread are cleaned up when it is terminated. If the background thread
+ // is stalled, it will be terminated when returning from main().
+ pthread_detach(thread);
}
- pthread_join(thread, nullptr);
return success;
}