mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-10 14:48:27 +00:00
Refactor the C API to eliminate memory leaks
This commit is contained in:
@@ -28,7 +28,7 @@ pub unsafe extern "C" fn wasm_trap_new(
|
||||
_store: &mut wasm_store_t,
|
||||
message: &wasm_message_t,
|
||||
) -> Option<Box<wasm_trap_t>> {
|
||||
let message_bytes = message.into_slice()?;
|
||||
let message_bytes = message.as_slice();
|
||||
|
||||
// The trap message is typed with `wasm_message_t` which is a
|
||||
// typeref to `wasm_name_t` with the exception that it's a
|
||||
@@ -117,10 +117,7 @@ pub unsafe extern "C" fn wasm_trap_message(
|
||||
let mut byte_vec = message.into_bytes();
|
||||
byte_vec.push(0);
|
||||
|
||||
let byte_vec: wasm_byte_vec_t = byte_vec.into();
|
||||
|
||||
out.size = byte_vec.size;
|
||||
out.data = byte_vec.data;
|
||||
out.set_buffer(byte_vec);
|
||||
}
|
||||
|
||||
/// Gets the origin frame attached to the trap.
|
||||
@@ -137,10 +134,12 @@ pub unsafe extern "C" fn wasm_trap_trace(
|
||||
out: &mut wasm_frame_vec_t,
|
||||
) {
|
||||
let frames = trap.inner.trace();
|
||||
let frame_vec: wasm_frame_vec_t = frames.into();
|
||||
|
||||
out.size = frame_vec.size;
|
||||
out.data = frame_vec.data;
|
||||
out.set_buffer(
|
||||
frames
|
||||
.iter()
|
||||
.map(|frame| Some(Box::new(frame.into())))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user