diff --git a/samples/csr-rust/Makefile b/samples/csr-rust/Makefile index 5f5339a2..72918f60 100644 --- a/samples/csr-rust/Makefile +++ b/samples/csr-rust/Makefile @@ -1,3 +1,2 @@ rust-sample: cargo build --release - cp target/wasm32-unknown-unknown/release/csr-rust.wasm . diff --git a/samples/csr-rust/src/main.rs b/samples/csr-rust/src/main.rs index 9f6b4808..df1b0fb7 100644 --- a/samples/csr-rust/src/main.rs +++ b/samples/csr-rust/src/main.rs @@ -79,7 +79,13 @@ pub unsafe extern "C" fn csr_gen(priv_key: &[u8]) -> i64 { Err(err) => { println!("error encoding cert request: {}", err); return 0 }, }; - ((encoded_csr.as_ptr() as i64) << 32) | (encoded_csr.len() as i64) + let encoded_csr_ptr = encoded_csr.as_ptr(); + let encoded_csr_len = encoded_csr.len(); + + // We must tell the rust compiler to abandon the buffer otherwise it will be freed before we can use it at the host side. + std::mem::forget(encoded_csr); + + ((encoded_csr_ptr as i64) << 32) | (encoded_csr_len as i64) } fn main() {} \ No newline at end of file