mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-06-18 02:59:21 +00:00
Fix issues reported by Coverity (#2053)
Fix the potential dead lock issue reported by Coverity code analysis tool.
This commit is contained in:
parent
3977f0b22a
commit
c7cdb78394
|
@ -253,6 +253,7 @@ acquire_wait_info(void *address, AtomicWaitNode *wait_node)
|
||||||
wait_info->wait_list = &wait_info->wait_list_head;
|
wait_info->wait_list = &wait_info->wait_list_head;
|
||||||
ret = bh_list_init(wait_info->wait_list);
|
ret = bh_list_init(wait_info->wait_list);
|
||||||
bh_assert(ret == BH_LIST_SUCCESS);
|
bh_assert(ret == BH_LIST_SUCCESS);
|
||||||
|
(void)ret;
|
||||||
|
|
||||||
if (!bh_hash_map_insert(wait_map, address, (void *)wait_info)) {
|
if (!bh_hash_map_insert(wait_map, address, (void *)wait_info)) {
|
||||||
wasm_runtime_free(wait_info);
|
wasm_runtime_free(wait_info);
|
||||||
|
|
|
@ -382,9 +382,9 @@ wasm_cluster_add_exec_env(WASMCluster *cluster, WASMExecEnv *exec_env)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The caller should lock cluster->lock for thread safety */
|
static bool
|
||||||
bool
|
wasm_cluster_del_exec_env_internal(WASMCluster *cluster, WASMExecEnv *exec_env,
|
||||||
wasm_cluster_del_exec_env(WASMCluster *cluster, WASMExecEnv *exec_env)
|
bool can_destroy_cluster)
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
bh_assert(exec_env->cluster == cluster);
|
bh_assert(exec_env->cluster == cluster);
|
||||||
|
@ -407,13 +407,26 @@ wasm_cluster_del_exec_env(WASMCluster *cluster, WASMExecEnv *exec_env)
|
||||||
if (bh_list_remove(&cluster->exec_env_list, exec_env) != 0)
|
if (bh_list_remove(&cluster->exec_env_list, exec_env) != 0)
|
||||||
ret = false;
|
ret = false;
|
||||||
|
|
||||||
|
if (can_destroy_cluster) {
|
||||||
if (cluster->exec_env_list.len == 0) {
|
if (cluster->exec_env_list.len == 0) {
|
||||||
/* exec_env_list empty, destroy the cluster */
|
/* exec_env_list empty, destroy the cluster */
|
||||||
wasm_cluster_destroy(cluster);
|
wasm_cluster_destroy(cluster);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Don't destroy cluster as cluster->lock is being used */
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The caller should lock cluster->lock for thread safety */
|
||||||
|
bool
|
||||||
|
wasm_cluster_del_exec_env(WASMCluster *cluster, WASMExecEnv *exec_env)
|
||||||
|
{
|
||||||
|
return wasm_cluster_del_exec_env_internal(cluster, exec_env, true);
|
||||||
|
}
|
||||||
|
|
||||||
static WASMExecEnv *
|
static WASMExecEnv *
|
||||||
wasm_cluster_search_exec_env(WASMCluster *cluster,
|
wasm_cluster_search_exec_env(WASMCluster *cluster,
|
||||||
WASMModuleInstanceCommon *module_inst)
|
WASMModuleInstanceCommon *module_inst)
|
||||||
|
@ -561,7 +574,7 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
|
||||||
/* Free aux stack space */
|
/* Free aux stack space */
|
||||||
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
|
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
|
||||||
/* Remove exec_env */
|
/* Remove exec_env */
|
||||||
wasm_cluster_del_exec_env(cluster, exec_env);
|
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
|
||||||
/* Destroy exec_env */
|
/* Destroy exec_env */
|
||||||
wasm_exec_env_destroy_internal(exec_env);
|
wasm_exec_env_destroy_internal(exec_env);
|
||||||
/* Routine exit, destroy instance */
|
/* Routine exit, destroy instance */
|
||||||
|
@ -621,7 +634,7 @@ thread_manager_start_routine(void *arg)
|
||||||
/* Free aux stack space */
|
/* Free aux stack space */
|
||||||
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
|
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
|
||||||
/* Remove exec_env */
|
/* Remove exec_env */
|
||||||
wasm_cluster_del_exec_env(cluster, exec_env);
|
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
|
||||||
/* Destroy exec_env */
|
/* Destroy exec_env */
|
||||||
wasm_exec_env_destroy_internal(exec_env);
|
wasm_exec_env_destroy_internal(exec_env);
|
||||||
/* Routine exit, destroy instance */
|
/* Routine exit, destroy instance */
|
||||||
|
@ -707,7 +720,7 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail4:
|
fail4:
|
||||||
wasm_cluster_del_exec_env(cluster, new_exec_env);
|
wasm_cluster_del_exec_env_internal(cluster, new_exec_env, false);
|
||||||
fail3:
|
fail3:
|
||||||
/* free the allocated aux stack space */
|
/* free the allocated aux stack space */
|
||||||
if (alloc_aux_stack)
|
if (alloc_aux_stack)
|
||||||
|
@ -972,7 +985,7 @@ wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval)
|
||||||
/* Free aux stack space */
|
/* Free aux stack space */
|
||||||
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
|
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
|
||||||
/* Remove exec_env */
|
/* Remove exec_env */
|
||||||
wasm_cluster_del_exec_env(cluster, exec_env);
|
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
|
||||||
/* Destroy exec_env */
|
/* Destroy exec_env */
|
||||||
wasm_exec_env_destroy_internal(exec_env);
|
wasm_exec_env_destroy_internal(exec_env);
|
||||||
/* Routine exit, destroy instance */
|
/* Routine exit, destroy instance */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user