Explorar o código

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
Enrico Loparco %!s(int64=2) %!d(string=hai) anos
pai
achega
892a94fd05
Modificáronse 1 ficheiros con 6 adicións e 4 borrados
  1. 6 4
      core/iwasm/common/wasm_c_api.c

+ 6 - 4
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;