Add a workaround for wasm memory leak (#282)

* Add a workaround for wasm memory leak

* fmt
This commit is contained in:
Valery Antopol 2022-07-08 17:29:26 +03:00 committed by GitHub
parent 0eb37800b6
commit 8bd4aa5783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,29 @@ use marine_rs_sdk::module_manifest;
module_manifest!();
/*
_initialize function that calls __wasm_call_ctors is required to mitigate memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298.
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
TODO: remove when updating to marine-rs-sdk with fix
*/
extern "C" {
fn __wasm_call_ctors();
}
#[no_mangle]
pub fn _initialize() {
unsafe {
__wasm_call_ctors();
}
}
pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module.
logger::init_logger(None);
}