From 19160f0e1de20068572aef46fb76d6052624d25a Mon Sep 17 00:00:00 2001 From: WenLY1 <130950131+WenLY1@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:56:36 +0800 Subject: [PATCH] Fix issues of destroy_shared_heaps (#3847) Set shared_heap_list to NULL with lock, and destroy shared_heap_list_lock. Signed-off-by: wenlingyun1 --- core/iwasm/common/wasm_memory.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/iwasm/common/wasm_memory.c b/core/iwasm/common/wasm_memory.c index d2d89e59..5f5a1be9 100644 --- a/core/iwasm/common/wasm_memory.c +++ b/core/iwasm/common/wasm_memory.c @@ -534,10 +534,15 @@ wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type, static void destroy_shared_heaps() { - WASMSharedHeap *heap = shared_heap_list; + WASMSharedHeap *heap; WASMSharedHeap *cur; uint64 map_size; + os_mutex_lock(&shared_heap_list_lock); + heap = shared_heap_list; + shared_heap_list = NULL; + os_mutex_unlock(&shared_heap_list_lock); + while (heap) { cur = heap; heap = heap->next; @@ -551,6 +556,7 @@ destroy_shared_heaps() wasm_munmap_linear_memory(cur->base_addr, cur->size, map_size); wasm_runtime_free(cur); } + os_mutex_destroy(&shared_heap_list_lock); } #endif