Просмотр исходного кода

Fix several memory leak issues (#2445)

Xu Jun 2 лет назад
Родитель
Сommit
a051dd7051

+ 2 - 3
core/iwasm/interpreter/wasm_loader.c

@@ -5488,11 +5488,10 @@ wasm_loader_unload(WASMModule *module)
 #endif
 #endif
 #if WASM_ENABLE_GC != 0
-                /* TODO
-                if (module->functions[i]->local_ref_type_maps)
+                if (module->functions[i]->local_ref_type_maps) {
                     wasm_runtime_free(
                         module->functions[i]->local_ref_type_maps);
-                */
+                }
 #endif
                 wasm_runtime_free(module->functions[i]);
             }

+ 1 - 1
core/shared/mem-alloc/ems/ems_alloc.c

@@ -961,7 +961,7 @@ gc_search_extra_info_node(gc_handle_t handle, gc_object_t obj,
     if (!vheap->extra_info_nodes)
         return NULL;
 
-    while (low < high) {
+    while (low <= high) {
         mid = (low + high) / 2;
         node = vheap->extra_info_nodes[mid];
 

+ 5 - 1
core/shared/mem-alloc/ems/ems_kfc.c

@@ -139,10 +139,14 @@ gc_destroy_with_pool(gc_handle_t handle)
 
     if (heap->extra_info_node_cnt > 0) {
         for (i = 0; i < heap->extra_info_node_cnt; i++) {
+            extra_info_node_t *node = heap->extra_info_nodes[i];
 #if BH_ENABLE_GC_VERIFY != 0
             os_printf("Memory leak detected: gc object [%p] not claimed\n",
-                      heap->extra_info_nodes[i]->obj);
+                      node->obj);
 #endif
+            bh_assert(heap->is_reclaim_enabled);
+            node->finalizer(node->obj, node->data);
+
             BH_FREE(heap->extra_info_nodes[i]);
         }