Explorar el Código

Allocate correct space for results before native callback is run (#747)

Saju Pillai hace 4 años
padre
commit
b1173d1bfc
Se han modificado 1 ficheros con 7 adiciones y 7 borrados
  1. 7 7
      core/iwasm/common/wasm_runtime_common.c

+ 7 - 7
core/iwasm/common/wasm_runtime_common.c

@@ -4117,6 +4117,13 @@ wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
         goto fail;
     }
 
+    if (func_type->result_count > 4
+        && !(results = wasm_runtime_malloc(sizeof(wasm_val_t)
+                                           * func_type->result_count))) {
+        wasm_runtime_set_exception(module_inst, "allocate memory failed");
+        goto fail;
+    }
+
     if (!with_env) {
         wasm_func_callback_t callback = (wasm_func_callback_t)func_ptr;
         trap = callback(params, results);
@@ -4144,13 +4151,6 @@ wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
         goto fail;
     }
 
-    if (func_type->result_count > 4
-        && !(results = wasm_runtime_malloc(sizeof(wasm_val_t)
-                                           * func_type->result_count))) {
-        wasm_runtime_set_exception(module_inst, "allocate memory failed");
-        goto fail;
-    }
-
     if (!results_to_argv(module_inst, argv, results, func_type)) {
         wasm_runtime_set_exception(module_inst, "unsupported result type");
         goto fail;