Skip to content

Commit 8f2aee4

Browse files
Lend object if and only if eval ends without exception
1 parent 945f4e1 commit 8f2aee4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/witapi/witapi-core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ void rb_abi_guest_rb_eval_string_protect(rb_abi_guest_string_t *str,
166166
VALUE retval;
167167
RB_WASM_DEBUG_LOG("rb_eval_string_protect: str = %s\n", str->ptr);
168168
RB_WASM_LIB_RT(retval = rb_eval_string_protect(str->ptr, state));
169-
rb_abi_lend_object(retval);
170169
RB_WASM_DEBUG_LOG("rb_eval_string_protect: retval = %p, state = %d\n", (void *)retval, *state);
171170

171+
if (*state == TAG_NONE) {
172+
rb_abi_lend_object(retval);
173+
}
172174
*result = rb_abi_guest_rb_abi_value_new((void *)retval);
173175
}
174176

@@ -197,9 +199,11 @@ void rb_abi_guest_rb_funcallv_protect(rb_abi_guest_rb_abi_value_t recv,
197199
struct rb_funcallv_thunk_ctx ctx = {
198200
.recv = r_recv, .mid = mid, .args = args};
199201
RB_WASM_LIB_RT(retval = rb_protect(rb_funcallv_thunk, (VALUE)&ctx, ret1));
200-
rb_abi_lend_object(retval);
201202
RB_WASM_DEBUG_LOG("rb_abi_guest_rb_funcallv_protect: retval = %p, state = %d\n", (void *)retval, *ret1);
202203

204+
if (*ret1 == TAG_NONE) {
205+
rb_abi_lend_object(retval);
206+
}
203207
*ret0 = rb_abi_guest_rb_abi_value_new((void *)retval);
204208
}
205209

0 commit comments

Comments
 (0)