Skip to content

Commit edf8221

Browse files
committed
Fix leak in test
1 parent c91dd31 commit edf8221

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

crates/c-api/include/wasmtime/exnref.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,17 @@ wasmtime_exnref_field(wasmtime_context_t *store, const wasmtime_exnref_t *exn,
128128
/**
129129
* \brief Sets the pending exception on the store and returns a trap.
130130
*
131-
* This transfers ownership of `exn` to the store. After this call,
132-
* the caller must not use or free `exn`.
133-
*
134131
* Returns a `wasm_trap_t` that the host callback MUST return to signal
135132
* to the Wasm runtime that an exception was thrown. The caller owns
136133
* the returned trap.
137134
*
138135
* \param store the store context
139-
* \param exn the exception to throw (ownership transferred)
136+
* \param exn the exception to throw
140137
* \return a trap to return from the host callback (caller-owned)
141138
*/
142139
WASM_API_EXTERN wasm_trap_t *
143140
wasmtime_context_set_exception(wasmtime_context_t *store,
144-
wasmtime_exnref_t *exn);
141+
const wasmtime_exnref_t *exn);
145142

146143
/**
147144
* \brief Takes the pending exception from the store, if any.

crates/c-api/include/wasmtime/store.hh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ inline Store::Context::Context(Caller *caller) : Context(*caller) {}
4444

4545
#ifdef WASMTIME_FEATURE_GC
4646
inline Trap Store::Context::throw_exception(ExnRef exn) {
47-
auto *ret = wasmtime_context_set_exception(capi(), exn.capi());
48-
wasmtime_exnref_set_null(exn.capi());
49-
return Trap(ret);
47+
return Trap(wasmtime_context_set_exception(capi(), exn.capi()));
5048
}
5149

5250
inline std::optional<ExnRef> Store::Context::take_exception() {

crates/c-api/src/exnref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub unsafe extern "C" fn wasmtime_exnref_field(
8383
#[unsafe(no_mangle)]
8484
pub unsafe extern "C" fn wasmtime_context_set_exception(
8585
mut store: WasmtimeStoreContextMut<'_>,
86-
exn: &mut wasmtime_exnref_t,
86+
exn: &wasmtime_exnref_t,
8787
) -> Option<Box<wasm_trap_t>> {
8888
let mut scope = RootScope::new(&mut store);
8989
let rooted = exn.as_wasmtime()?.to_rooted(&mut scope);

crates/c-api/tests/exception.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ TEST(Exception, HostThrowWasmCatch) {
9898

9999
std::vector<Val> fields = {Val(int32_t(99))};
100100
auto exn = ExnRef::create(cx2, tag, fields).unwrap();
101-
return cx2.throw_exception(std::move(exn));
101+
return cx2.throw_exception(exn);
102102
});
103103

104104
std::vector<Extern> imports = {throw_fn, tag};

0 commit comments

Comments
 (0)