diff --git a/examples/allocation/rust/greet.go b/examples/allocation/rust/greet.go index 3d19eec3..e2d4b8f1 100644 --- a/examples/allocation/rust/greet.go +++ b/examples/allocation/rust/greet.go @@ -88,7 +88,12 @@ func main() { greetingSize := uint32(ptrSize[0]) // This pointer was allocated by Rust, but owned by Go, So, we have to // deallocate it when finished - defer deallocate.Call(ctx, uint64(greetingPtr), uint64(greetingSize)) + defer func() { + _, err = deallocate.Call(ctx, uint64(greetingPtr), uint64(greetingSize)) + if err != nil { + log.Panicln(err) + } + }() // The pointer is a linear memory offset, which is where we write the name. if bytes, ok := mod.Memory().Read(greetingPtr, greetingSize); !ok { diff --git a/examples/allocation/rust/testdata/greet.rs b/examples/allocation/rust/testdata/greet.rs index 962dbf1c..54b17558 100644 --- a/examples/allocation/rust/testdata/greet.rs +++ b/examples/allocation/rust/testdata/greet.rs @@ -101,7 +101,7 @@ pub extern "C" fn _allocate(size: u32) -> *mut u8 { /// Allocates size bytes and leaks the pointer where they start. fn allocate(size: usize) -> *mut u8 { // Allocate the amount of bytes needed. - let vec: Vec> = Vec::with_capacity(size); + let vec: Vec> = vec![MaybeUninit::uninit(); size]; // into_raw leaks the memory to the caller. Box::into_raw(vec.into_boxed_slice()) as *mut u8 diff --git a/examples/allocation/rust/testdata/greet.wasm b/examples/allocation/rust/testdata/greet.wasm index 28ca86a1..0fc12f75 100755 Binary files a/examples/allocation/rust/testdata/greet.wasm and b/examples/allocation/rust/testdata/greet.wasm differ