Remove unused block_addr_cache buffer in wasm loader (#493)

And fix possible memory leak issue in aot loader when apply relocation failed.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Wenyong Huang 2021-01-08 05:11:12 -06:00 committed by GitHub
parent 788cbf2a19
commit 8a477786f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 17 deletions

View File

@ -1584,11 +1584,11 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
#endif
) {
if (!do_text_relocation(module, group, error_buf, error_buf_size))
return false;
goto fail;
}
else {
if (!do_data_relocation(module, group, error_buf, error_buf_size))
return false;
goto fail;
}
}

View File

@ -2518,7 +2518,6 @@ fail:
static bool
wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
BlockAddr *block_addr_cache,
char *error_buf, uint32 error_buf_size);
#if WASM_ENABLE_FAST_INTERP != 0
@ -2542,9 +2541,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
uint32 aux_stack_top = (uint32)-1, global_index, func_index, i;
uint32 aux_data_end_global_index = (uint32)-1;
uint32 aux_heap_base_global_index = (uint32)-1;
BlockAddr *block_addr_cache;
WASMType *func_type;
uint64 total_size;
/* Find code and function sections if have */
while (section) {
@ -2828,23 +2825,13 @@ load_from_sections(WASMModule *module, WASMSection *sections,
handle_table = wasm_interp_get_handle_table();
#endif
total_size = sizeof(BlockAddr) * (uint64)BLOCK_ADDR_CACHE_SIZE
* BLOCK_ADDR_CONFLICT_SIZE;
if (!(block_addr_cache = loader_malloc
(total_size, error_buf, error_buf_size))) {
return false;
}
for (i = 0; i < module->function_count; i++) {
WASMFunction *func = module->functions[i];
memset(block_addr_cache, 0, (uint32)total_size);
if (!wasm_loader_prepare_bytecode(module, func, block_addr_cache,
if (!wasm_loader_prepare_bytecode(module, func,
error_buf, error_buf_size)) {
wasm_runtime_free(block_addr_cache);
return false;
}
}
wasm_runtime_free(block_addr_cache);
if (!module->possible_memory_grow) {
WASMMemoryImport *memory_import;
@ -5692,7 +5679,6 @@ fail:
static bool
wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
BlockAddr *block_addr_cache,
char *error_buf, uint32 error_buf_size)
{
uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org;