From e15db8d732ab6f776b536939e8adb68412644724 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 22 Aug 2022 14:52:33 +0800 Subject: [PATCH] Destroy fast-jit compiler after destroy loaded modules (#1402) Destroy Fast-JIT compiler after destroying the modules loaded by multi-module feature, since the Fast JIT's code cache allocator may be used by these modules. If the Fast JIT's code cache allocator was destroyed, then runtime will fail to destroy these modules. And fix the issue of destroying import module's memory instance. --- core/iwasm/common/wasm_runtime_common.c | 12 ++++++++---- core/iwasm/interpreter/wasm_runtime.c | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 4ee42601..7562877c 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -341,10 +341,6 @@ wasm_runtime_init() void wasm_runtime_destroy() { -#if WASM_ENABLE_FAST_JIT != 0 - jit_compiler_destroy(); -#endif - #if WASM_ENABLE_REF_TYPES != 0 wasm_externref_map_destroy(); #endif @@ -368,6 +364,14 @@ wasm_runtime_destroy() os_mutex_destroy(®istered_module_list_lock); #endif +#if WASM_ENABLE_FAST_JIT != 0 + /* Destroy Fast-JIT compiler after destroying the modules + * loaded by multi-module feature, since the Fast JIT's + * code cache allocator may be used by these modules. + */ + jit_compiler_destroy(); +#endif + #if WASM_ENABLE_SHARED_MEMORY wasm_shared_memory_destroy(); #endif diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 20b6a045..e76f3b00 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -109,8 +109,11 @@ memories_deinstantiate(WASMModuleInstance *module_inst, for (i = 0; i < count; i++) { if (memories[i]) { #if WASM_ENABLE_MULTI_MODULE != 0 - if (i < module_inst->module->import_memory_count) + WASMModule *module = module_inst->module; + if (i < module->import_memory_count + && module->import_memories[i].u.memory.import_module) { continue; + } #endif #if WASM_ENABLE_SHARED_MEMORY != 0 if (memories[i]->is_shared) {