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
This commit is contained in:
Enrico Loparco 2024-01-15 11:18:37 +01:00 committed by GitHub
parent 837b9904f5
commit 892a94fd05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;