Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2daedf5 authored by Yifan Hong's avatar Yifan Hong
Browse files

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
parent a4f2d92c
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -72,10 +72,14 @@ bool timeout(std::chrono::duration<R, P> delay, std::function<void(void)> &&func
        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);
    }
    return success;
}

+1 −0
Original line number Diff line number Diff line
@@ -18,5 +18,6 @@

int main(int argc, char **argv) {
    using namespace ::android::lshal;
    // Background pthreads from timeout() are destroyed upon returning from main().
    return Lshal{}.main(Arg{argc, argv});
}