mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-26 15:52:14 +00:00
Add a workaround for wasm memory leak (#282)
* Add a workaround for wasm memory leak * fmt
This commit is contained in:
parent
0eb37800b6
commit
8bd4aa5783
@ -37,7 +37,29 @@ use marine_rs_sdk::module_manifest;
|
|||||||
|
|
||||||
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() {
|
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);
|
logger::init_logger(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user