From 892a94fd05f2e95fc68535d763bf67ab1b8e6263 Mon Sep 17 00:00:00 2001 From: Enrico Loparco Date: Mon, 15 Jan 2024 11:18:37 +0100 Subject: [PATCH] fix(wasm-c-api): Do not clone stack frames if there's no trap (#3008) When running the wasi-threads no_pthread sample, the assert was failing on `src->num_elems != 0` in debug mode, it is because that the exception is `proc_exit`, there is no trap (the execution didn't fail, no stack frames): https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/samples/wasi-threads/wasm-apps/no_pthread.c --- core/iwasm/common/wasm_c_api.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 27b1e0405..bdc5315eb 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -1924,14 +1924,16 @@ wasm_frame_func_offset(const wasm_frame_t *frame) void wasm_frame_vec_clone_internal(Vector *src, Vector *out) { - bh_assert(src->num_elems != 0 && src->data); - - bh_vector_destroy(out); - if (!bh_vector_init(out, src->num_elems, sizeof(WASMCApiFrame), false)) { + if (src->num_elems == 0) { bh_vector_destroy(out); return; } + if (!bh_vector_destroy(out) + || !bh_vector_init(out, src->num_elems, sizeof(WASMCApiFrame), false)) { + return; + } + bh_memcpy_s(out->data, src->num_elems * sizeof(WASMCApiFrame), src->data, src->num_elems * sizeof(WASMCApiFrame)); out->num_elems = src->num_elems;