Преглед на файлове

Move wasm_runtime_destroy_wasi and wasi_nn_destroy calls together (#2418)

And remove obsolete comment.
YAMAMOTO Takashi преди 2 години
родител
ревизия
28125ec538
променени са 2 файла, в които са добавени 10 реда и са изтрити 22 реда
  1. 5 11
      core/iwasm/aot/aot_runtime.c
  2. 5 11
      core/iwasm/interpreter/wasm_runtime.c

+ 5 - 11
core/iwasm/aot/aot_runtime.c

@@ -1264,16 +1264,6 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
         wasm_exec_env_destroy((WASMExecEnv *)module_inst->exec_env_singleton);
         wasm_exec_env_destroy((WASMExecEnv *)module_inst->exec_env_singleton);
     }
     }
 
 
-#if WASM_ENABLE_LIBC_WASI != 0
-    /* Destroy wasi resource before freeing app heap, since some fields of
-       wasi contex are allocated from app heap, and if app heap is freed,
-       these fields will be set to NULL, we cannot free their internal data
-       which may allocated from global heap. */
-    /* Only destroy wasi ctx in the main module instance */
-    if (!is_sub_inst)
-        wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst);
-#endif
-
 #if WASM_ENABLE_PERF_PROFILING != 0
 #if WASM_ENABLE_PERF_PROFILING != 0
     if (module_inst->func_perf_profilings)
     if (module_inst->func_perf_profilings)
         wasm_runtime_free(module_inst->func_perf_profilings);
         wasm_runtime_free(module_inst->func_perf_profilings);
@@ -1306,10 +1296,14 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
         wasm_runtime_free(
         wasm_runtime_free(
             ((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports);
             ((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports);
 
 
+    if (!is_sub_inst) {
+#if WASM_ENABLE_LIBC_WASI != 0
+        wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst);
+#endif
 #if WASM_ENABLE_WASI_NN != 0
 #if WASM_ENABLE_WASI_NN != 0
-    if (!is_sub_inst)
         wasi_nn_destroy(module_inst);
         wasi_nn_destroy(module_inst);
 #endif
 #endif
+    }
 
 
     wasm_runtime_free(module_inst);
     wasm_runtime_free(module_inst);
 }
 }

+ 5 - 11
core/iwasm/interpreter/wasm_runtime.c

@@ -2216,16 +2216,6 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
     sub_module_deinstantiate(module_inst);
     sub_module_deinstantiate(module_inst);
 #endif
 #endif
 
 
-#if WASM_ENABLE_LIBC_WASI != 0
-    /* Destroy wasi resource before freeing app heap, since some fields of
-       wasi contex are allocated from app heap, and if app heap is freed,
-       these fields will be set to NULL, we cannot free their internal data
-       which may allocated from global heap. */
-    /* Only destroy wasi ctx in the main module instance */
-    if (!is_sub_inst)
-        wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst);
-#endif
-
     if (module_inst->memory_count > 0)
     if (module_inst->memory_count > 0)
         memories_deinstantiate(module_inst, module_inst->memories,
         memories_deinstantiate(module_inst, module_inst->memories,
                                module_inst->memory_count);
                                module_inst->memory_count);
@@ -2258,10 +2248,14 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
     if (module_inst->e->c_api_func_imports)
     if (module_inst->e->c_api_func_imports)
         wasm_runtime_free(module_inst->e->c_api_func_imports);
         wasm_runtime_free(module_inst->e->c_api_func_imports);
 
 
+    if (!is_sub_inst) {
+#if WASM_ENABLE_LIBC_WASI != 0
+        wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst);
+#endif
 #if WASM_ENABLE_WASI_NN != 0
 #if WASM_ENABLE_WASI_NN != 0
-    if (!is_sub_inst)
         wasi_nn_destroy(module_inst);
         wasi_nn_destroy(module_inst);
 #endif
 #endif
+    }
 
 
     wasm_runtime_free(module_inst);
     wasm_runtime_free(module_inst);
 }
 }