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

This commit is contained in:
Saju Pillai
2021-09-13 09:55:05 +08:00
committed by GitHub
parent e07b58062f
commit b1173d1bfc
+7 -7
View File
@@ -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;