From edaff3c6ec2063595d15fc075577db659ca34e5f Mon Sep 17 00:00:00 2001 From: Shengyun Zhou Date: Thu, 15 Sep 2022 17:13:33 +0800 Subject: [PATCH] thread-mgr: Prevent an already detached thread from being detached again (#1487) If WASM app has called pthread_detach() to detach a thread, it will be detached again when thread exits. Attempting to detach an already detached thread may result in crash in musl-libc. This patch fixes it. --- core/iwasm/libraries/thread-mgr/thread_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/libraries/thread-mgr/thread_manager.c b/core/iwasm/libraries/thread-mgr/thread_manager.c index 93212b0c..2e15ac54 100644 --- a/core/iwasm/libraries/thread-mgr/thread_manager.c +++ b/core/iwasm/libraries/thread-mgr/thread_manager.c @@ -705,7 +705,7 @@ wasm_cluster_detach_thread(WASMExecEnv *exec_env) os_mutex_unlock(&cluster_list_lock); return 0; } - if (exec_env->wait_count == 0) { + if (exec_env->wait_count == 0 && !exec_env->thread_is_detached) { /* Only detach current thread when there is no other thread joining it, otherwise let the system resources for the thread be released after joining */