Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions core/iwasm/common/wasm_c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2206,12 +2206,15 @@ check_loaded_module(Vector *modules, char *binary_hash)
return NULL;
}

if (!module->ref_count)
/* deleted */
continue;
os_mutex_lock(&module->lock);
bool is_valid =
(module->ref_count > 0
&& memcmp(module->hash, binary_hash, SHA256_DIGEST_LENGTH) == 0);
os_mutex_unlock(&module->lock);

if (memcmp(module->hash, binary_hash, SHA256_DIGEST_LENGTH) == 0)
if (is_valid) {
return module;
}
}
return NULL;
}
Expand Down Expand Up @@ -2456,8 +2459,13 @@ wasm_module_imports(const wasm_module_t *module, own wasm_importtype_vec_t *out)
return;
}

if (((const wasm_module_ex_t *)(module))->ref_count == 0)
wasm_module_ex_t *module_ex = module_to_module_ext((wasm_module_t *)module);
os_mutex_lock(&module_ex->lock);
if (module_ex->ref_count == 0) {
os_mutex_unlock(&module_ex->lock);
return;
}
os_mutex_unlock(&module_ex->lock);

#if WASM_ENABLE_INTERP != 0
if ((*module)->module_type == Wasm_Module_Bytecode) {
Expand Down Expand Up @@ -2696,8 +2704,13 @@ wasm_module_exports(const wasm_module_t *module, wasm_exporttype_vec_t *out)
return;
}

if (((const wasm_module_ex_t *)(module))->ref_count == 0)
wasm_module_ex_t *module_ex = module_to_module_ext((wasm_module_t *)module);
os_mutex_lock(&module_ex->lock);
if (module_ex->ref_count == 0) {
os_mutex_unlock(&module_ex->lock);
return;
}
os_mutex_unlock(&module_ex->lock);

#if WASM_ENABLE_INTERP != 0
if ((*module)->module_type == Wasm_Module_Bytecode) {
Expand Down Expand Up @@ -2891,10 +2904,13 @@ wasm_module_serialize(wasm_module_t *module, own wasm_byte_vec_t *out)
if (!module || !out)
return;

if (((const wasm_module_ex_t *)(module))->ref_count == 0)
return;

module_ex = module_to_module_ext(module);
os_mutex_lock(&module_ex->lock);
if (module_ex->ref_count == 0) {
os_mutex_unlock(&module_ex->lock);
return;
}
os_mutex_unlock(&module_ex->lock);
comp_ctx = ((WASMModule *)(module_ex->module_comm_rt))->comp_ctx;
comp_data = ((WASMModule *)(module_ex->module_comm_rt))->comp_data;
bh_assert(comp_ctx != NULL && comp_data != NULL);
Expand Down
Loading