Add memory leak temporary mitigation (#42)

This commit is contained in:
Valery Antopol 2022-06-28 18:40:19 +03:00 committed by GitHub
parent b9fbbbcafb
commit aa72fdab64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 6 deletions

2
Cargo.lock generated
View File

@ -2672,7 +2672,7 @@ dependencies = [
[[package]]
name = "trust-graph-wasm"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"anyhow",
"bincode",

View File

@ -1,6 +1,6 @@
[package]
name = "trust-graph-wasm"
version = "0.3.0"
version = "0.3.1"
authors = ["Fluence Labs"]
edition = "2018"
description = "trust graph wasm"

View File

@ -13,10 +13,31 @@ mod results;
mod service_api;
mod storage_impl;
mod tests;
/*
_initialize function that calls __wasm_call_ctors is required to mitigade 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" {
pub fn __wasm_call_ctors();
}
#[no_mangle]
fn _initialize() {
unsafe {
__wasm_call_ctors();
}
}
//------------------------------
pub static TRUSTED_TIMESTAMP: (&str, &str) = ("peer", "timestamp_sec");
pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module
WasmLoggerBuilder::new()
.with_log_level(log::LevelFilter::Trace)
.build()