Skip to content

Commit 8a47778

Browse files
authored
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>
1 parent 788cbf2 commit 8a47778

2 files changed

Lines changed: 3 additions & 17 deletions

File tree

core/iwasm/aot/aot_loader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,11 +1584,11 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
15841584
#endif
15851585
) {
15861586
if (!do_text_relocation(module, group, error_buf, error_buf_size))
1587-
return false;
1587+
goto fail;
15881588
}
15891589
else {
15901590
if (!do_data_relocation(module, group, error_buf, error_buf_size))
1591-
return false;
1591+
goto fail;
15921592
}
15931593
}
15941594

core/iwasm/interpreter/wasm_loader.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,6 @@ load_user_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
25182518

25192519
static bool
25202520
wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
2521-
BlockAddr *block_addr_cache,
25222521
char *error_buf, uint32 error_buf_size);
25232522

25242523
#if WASM_ENABLE_FAST_INTERP != 0
@@ -2542,9 +2541,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
25422541
uint32 aux_stack_top = (uint32)-1, global_index, func_index, i;
25432542
uint32 aux_data_end_global_index = (uint32)-1;
25442543
uint32 aux_heap_base_global_index = (uint32)-1;
2545-
BlockAddr *block_addr_cache;
25462544
WASMType *func_type;
2547-
uint64 total_size;
25482545

25492546
/* Find code and function sections if have */
25502547
while (section) {
@@ -2828,23 +2825,13 @@ load_from_sections(WASMModule *module, WASMSection *sections,
28282825
handle_table = wasm_interp_get_handle_table();
28292826
#endif
28302827

2831-
total_size = sizeof(BlockAddr) * (uint64)BLOCK_ADDR_CACHE_SIZE
2832-
* BLOCK_ADDR_CONFLICT_SIZE;
2833-
if (!(block_addr_cache = loader_malloc
2834-
(total_size, error_buf, error_buf_size))) {
2835-
return false;
2836-
}
2837-
28382828
for (i = 0; i < module->function_count; i++) {
28392829
WASMFunction *func = module->functions[i];
2840-
memset(block_addr_cache, 0, (uint32)total_size);
2841-
if (!wasm_loader_prepare_bytecode(module, func, block_addr_cache,
2830+
if (!wasm_loader_prepare_bytecode(module, func,
28422831
error_buf, error_buf_size)) {
2843-
wasm_runtime_free(block_addr_cache);
28442832
return false;
28452833
}
28462834
}
2847-
wasm_runtime_free(block_addr_cache);
28482835

28492836
if (!module->possible_memory_grow) {
28502837
WASMMemoryImport *memory_import;
@@ -5692,7 +5679,6 @@ copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block,
56925679

56935680
static bool
56945681
wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
5695-
BlockAddr *block_addr_cache,
56965682
char *error_buf, uint32 error_buf_size)
56975683
{
56985684
uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org;

0 commit comments

Comments
 (0)