@@ -968,6 +968,35 @@ load_custom_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
968968 return false;
969969}
970970
971+ #if WASM_ENABLE_GC != 0 || WASM_ENABLE_EXTENDED_CONST_EXPR != 0
972+ static void
973+ destroy_init_expr (InitializerExpression * expr )
974+ {
975+ #if WASM_ENABLE_GC != 0
976+ if (expr -> init_expr_type == INIT_EXPR_TYPE_STRUCT_NEW
977+ || expr -> init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW
978+ || expr -> init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_FIXED ) {
979+ wasm_runtime_free (expr -> u .unary .v .data );
980+ }
981+ #endif
982+
983+ #if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
984+ // free left expr and right expr for binary oprand
985+ if (is_expr_binary_op (expr -> init_expr_type )) {
986+ return ;
987+ }
988+ if (expr -> u .binary .l_expr ) {
989+ destroy_init_expr_recursive (expr -> u .binary .l_expr );
990+ }
991+ if (expr -> u .binary .r_expr ) {
992+ destroy_init_expr_recursive (expr -> u .binary .r_expr );
993+ }
994+ expr -> u .binary .l_expr = expr -> u .binary .r_expr = NULL ;
995+ #endif
996+ }
997+ #endif /* end of WASM_ENABLE_GC != 0 || WASM_ENABLE_EXTENDED_CONST_EXPR != 0 \
998+ */
999+
9711000static void
9721001destroy_import_memories (AOTImportMemory * import_memories )
9731002{
@@ -994,9 +1023,7 @@ destroy_mem_init_data_list(AOTModule *module, AOTMemInitData **data_list,
9941023 if (module -> is_binary_freeable && data_list [i ]-> bytes )
9951024 wasm_runtime_free (data_list [i ]-> bytes );
9961025#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
997- if (is_expr_binary_op (data_list [i ]-> offset .init_expr_type )) {
998- destroy_sub_init_expr (& data_list [i ]-> offset );
999- }
1026+ destroy_init_expr (& data_list [i ]-> offset );
10001027#endif
10011028 /* Free the data segment structure itself */
10021029 wasm_runtime_free (data_list [i ]);
@@ -1067,8 +1094,7 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
10671094 data_list [i ]-> is_passive = (bool )is_passive ;
10681095 data_list [i ]-> memory_index = memory_index ;
10691096#endif
1070- bh_memcpy_s (& data_list [i ]-> offset , sizeof (InitializerExpression ),
1071- & offset_expr , sizeof (InitializerExpression ));
1097+ data_list [i ]-> offset = offset_expr ;
10721098 data_list [i ]-> byte_count = byte_count ;
10731099 data_list [i ]-> bytes = NULL ;
10741100 /* If the module owns the binary data, clone the bytes buffer */
@@ -1153,18 +1179,6 @@ load_memory_info(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
11531179 return false;
11541180}
11551181
1156- #if WASM_ENABLE_GC != 0
1157- static void
1158- destroy_init_expr (InitializerExpression * expr )
1159- {
1160- if (expr -> init_expr_type == INIT_EXPR_TYPE_STRUCT_NEW
1161- || expr -> init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW
1162- || expr -> init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_FIXED ) {
1163- wasm_runtime_free (expr -> u .unary .v .data );
1164- }
1165- }
1166- #endif /* end of WASM_ENABLE_GC != 0 */
1167-
11681182static void
11691183destroy_import_tables (AOTImportTable * import_tables )
11701184{
@@ -1191,7 +1205,7 @@ destroy_table_init_data_list(AOTTableInitData **data_list, uint32 count)
11911205#endif
11921206#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
11931207 if (is_expr_binary_op (data_list [i ]-> offset .init_expr_type )) {
1194- destroy_sub_init_expr (& data_list [i ]-> offset );
1208+ destroy_init_expr (& data_list [i ]-> offset );
11951209 }
11961210#endif
11971211 wasm_runtime_free (data_list [i ]);
@@ -1406,7 +1420,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
14061420 (void )free_if_fail ;
14071421#endif
14081422#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
1409- destroy_sub_init_expr (expr );
1423+ destroy_init_expr (expr );
14101424#endif
14111425 return false;
14121426}
@@ -1624,8 +1638,7 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
16241638 }
16251639 }
16261640#endif
1627- bh_memcpy_s (& data_list [i ]-> offset , sizeof (InitializerExpression ),
1628- & offset_expr , sizeof (InitializerExpression ));
1641+ data_list [i ]-> offset = offset_expr ;
16291642 data_list [i ]-> value_count = value_count ;
16301643 for (j = 0 ; j < data_list [i ]-> value_count ; j ++ ) {
16311644 if (!load_init_expr (& buf , buf_end , module ,
@@ -4516,20 +4529,11 @@ aot_unload(AOTModule *module)
45164529 destroy_import_globals (module -> import_globals );
45174530
45184531 if (module -> globals ) {
4519- #if WASM_ENABLE_GC != 0
4532+ #if WASM_ENABLE_GC != 0 || WASM_ENABLE_EXTENDED_CONST_EXPR != 0
45204533 uint32 i ;
45214534 for (i = 0 ; i < module -> global_count ; i ++ ) {
45224535 destroy_init_expr (& module -> globals [i ].init_expr );
45234536 }
4524- #endif
4525- #if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
4526- uint32 j ;
4527- for (j = 0 ; j < module -> global_count ; j ++ ) {
4528- if (is_expr_binary_op (
4529- module -> globals [j ].init_expr .init_expr_type )) {
4530- destroy_sub_init_expr (& module -> globals [j ].init_expr );
4531- }
4532- }
45334537#endif
45344538 destroy_globals (module -> globals );
45354539 }
0 commit comments