Add NULL check for memory inst in aot/wasm module malloc/free (#403)

* Add NULL check for memory page in aot/wasm module malloc/free

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>

* Update aot_runtime.c

* Update wasm_runtime.c

Co-authored-by: Huang Qi <huangqi3@xiaomi.com>
Co-authored-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Huang Qi
2020-09-28 12:44:23 +08:00
committed by GitHub
parent 4bfcbc2cab
commit 0bf7f7310b
2 changed files with 21 additions and 1 deletions

View File

@ -1575,6 +1575,11 @@ wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
uint8 *addr = NULL;
uint32 offset = 0;
if (!memory) {
wasm_set_exception(module_inst, "uninitialized memory");
return 0;
}
if (memory->heap_handle) {
addr = mem_allocator_malloc(memory->heap_handle, size);
}
@ -1606,7 +1611,13 @@ wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr)
{
if (ptr) {
WASMMemoryInstance *memory = module_inst->default_memory;
uint8 *addr = memory->memory_data + ptr;
uint8* addr;
if (!memory) {
return;
}
addr = memory->memory_data + ptr;
if (memory->heap_handle
&& memory->heap_data <= addr