Переглянути джерело

Collective fix (#4808)

* fix a bug in zephyr platform file api
* fix a bug in bh queue
* fix a bug in shared heap malloc when it's memory64
TianlongLiang 14 годин тому
батько
коміт
733ac3f19d

+ 3 - 4
core/iwasm/common/wasm_memory.c

@@ -796,10 +796,9 @@ wasm_runtime_shared_heap_malloc(WASMModuleInstanceCommon *module_inst,
         *p_native_addr = native_addr;
     }
 
-    return memory->is_memory64
-               ? shared_heap->start_off_mem64
-               : shared_heap->start_off_mem32
-                     + ((uint8 *)native_addr - shared_heap->base_addr);
+    return (memory->is_memory64 ? shared_heap->start_off_mem64
+                                : shared_heap->start_off_mem32)
+           + (uintptr_t)((uint8 *)native_addr - shared_heap->base_addr);
 }
 
 void

+ 1 - 0
core/shared/platform/zephyr/zephyr_file.c

@@ -451,6 +451,7 @@ os_openat(os_file_handle handle, const char *path, __wasi_oflags_t oflags,
     }
 
     if (!build_absolute_path(abs_path, sizeof(abs_path), path)) {
+        BH_FREE(*out);
         return __WASI_ENOMEM;
     }
 

+ 5 - 2
core/shared/utils/bh_queue.c

@@ -96,14 +96,15 @@ bh_queue_destroy(bh_queue *queue)
 bool
 bh_post_msg2(bh_queue *queue, bh_queue_node *msg)
 {
+    bh_queue_mutex_lock(&queue->queue_lock);
+
     if (queue->cnt >= queue->max) {
         queue->drops++;
         bh_free_msg(msg);
+        bh_queue_mutex_unlock(&queue->queue_lock);
         return false;
     }
 
-    bh_queue_mutex_lock(&queue->queue_lock);
-
     if (queue->cnt == 0) {
         bh_assert(queue->head == NULL);
         bh_assert(queue->tail == NULL);
@@ -131,7 +132,9 @@ bh_post_msg(bh_queue *queue, unsigned short tag, void *body, unsigned int len)
 {
     bh_queue_node *msg = bh_new_msg(tag, body, len, NULL);
     if (msg == NULL) {
+        bh_queue_mutex_lock(&queue->queue_lock);
         queue->drops++;
+        bh_queue_mutex_unlock(&queue->queue_lock);
         if (len != 0 && body)
             BH_FREE(body);
         return false;