From 2135badc54eb2ea937ffd370b7718ea983e501d6 Mon Sep 17 00:00:00 2001 From: Xu Jun <693788454@qq.com> Date: Mon, 7 Sep 2020 17:32:00 +0800 Subject: [PATCH] fix problem in wasm_module_malloc (#374) --- core/iwasm/interpreter/wasm_runtime.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index dee8ea98..f139ae3e 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1580,6 +1580,9 @@ wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size, size, &offset)) { return 0; } + /* If we use app's malloc function, + the default memory may be changed while memory growing */ + memory = module_inst->default_memory; addr = offset ? memory->memory_data + offset : NULL; } @@ -1589,6 +1592,7 @@ wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size, } if (p_native_addr) *p_native_addr = addr; + return (uint32)(addr - memory->memory_data); }