From 234f0e4b033f1d8d38a639309ec33d65e0b016a3 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 3 Oct 2023 12:21:45 +0200 Subject: [PATCH] Fix some calls to `free()` missing alignment --- CHANGELOG.md | 3 +++ crates/cli-support/src/js/binding.rs | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96f7ff54b0f..1cfb25f59bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -132,6 +132,9 @@ * Fix bug with function arguments coming from `macro_rules!`. [#3625](https://github.com/rustwasm/wasm-bindgen/pull/3625) +* Fix some calls to `free()` missing alignment. + [#3639](https://github.com/rustwasm/wasm-bindgen/pull/3639) + ### Removed * Removed `ReadableStreamByobReader::read_with_u8_array()` because it doesn't work with Wasm. diff --git a/crates/cli-support/src/js/binding.rs b/crates/cli-support/src/js/binding.rs index 1cd3e0f22da..c86927c6e8b 100644 --- a/crates/cli-support/src/js/binding.rs +++ b/crates/cli-support/src/js/binding.rs @@ -1056,7 +1056,7 @@ fn instruction( if *owned { let free = js.cx.export_name_of(*free); js.prelude(&format!( - "if ({ptr} !== 0) {{ wasm.{}({ptr}, {len}); }}", + "if ({ptr} !== 0) {{ wasm.{}({ptr}, {len}, 1); }}", free, ptr = ptr, len = len, @@ -1129,11 +1129,11 @@ fn instruction( let free = js.cx.export_name_of(*free); js.prelude(&format!("var v{} = {}({}, {}).slice();", i, f, ptr, len)); js.prelude(&format!( - "wasm.{}({}, {} * {});", + "wasm.{}({}, {} * {size}, {size});", free, ptr, len, - kind.size() + size = kind.size() )); js.push(format!("v{}", i)) } @@ -1148,11 +1148,11 @@ fn instruction( js.prelude(&format!("if ({} !== 0) {{", ptr)); js.prelude(&format!("v{} = {}({}, {}).slice();", i, f, ptr, len)); js.prelude(&format!( - "wasm.{}({}, {} * {});", + "wasm.{}({}, {} * {size}, {size});", free, ptr, len, - kind.size() + size = kind.size() )); js.prelude("}"); js.push(format!("v{}", i));