fix: avoid mutiple environ initializations which may lead to memory leak#390
fix: avoid mutiple environ initializations which may lead to memory leak#390wujunzhuo wants to merge 1 commit intoWebAssembly:mainfrom wujunzhuo:env
Conversation
|
can you explain how can it lead memory leak? |
|
We should not complicate wasi-libc ctor logic by trying to make them idempotent (or at least not leak memory or do other weird stuff when called twice). They are never meant to be called more than once. If the ctor is indeed called more than once, it's a misuse, due to targetting wasi command modules in old versions of The situation has been mitigated by #328. However, users should still explicitly pass |
|
The memory leak phenomenon is described in the issue #389, and it's very easy to reproduce.
It seems like this bug is due to the lack of passing reactor model type in Rustc/Cargo? |
That is not a wasi-libc issue.
Try [target.wasm32-wasi]
rustflags = ["-C", "link-arg=-mexec-model=reactor"] |
wujunzhuo@wujunzhuo-macbook wasm % cat ~/.cargo/config.toml
[target.wasm32-wasi]
rustflags = ["-C", "link-arg=-mexec-model=reactor"]
wujunzhuo@wujunzhuo-macbook wasm % cargo build --release --target wasm32-wasi
Compiling hello v0.1.0 (/Users/wujunzhuo/Desktop/hello/wasm)
error: linking with `rust-lld` failed: exit status: 1
|
= note: "rust-lld" "-flavor" "wasm" "--rsp-quoting=posix" "--export" "hello" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--fatal-warnings" "--no-demangle" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.hello.acc9aabb-cgu.0.rcgu.o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.hello.acc9aabb-cgu.1.rcgu.o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.hello.acc9aabb-cgu.2.rcgu.o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.hello.acc9aabb-cgu.3.rcgu.o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.hello.acc9aabb-cgu.4.rcgu.o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.hello.acc9aabb-cgu.5.rcgu.o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.hello.acc9aabb-cgu.6.rcgu.o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.1ykrkc27kh9t6on3.rcgu.o" "-L" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps" "-L" "/Users/wujunzhuo/Desktop/hello/wasm/target/release/deps" "-L" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libstd-09fa6ca09f86d164.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libpanic_abort-c3e95cd39c57a54c.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libwasi-fbb489748f675963.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/librustc_demangle-cd39d41079a84f6f.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libstd_detect-a0fc91e2cfaf61dd.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libhashbrown-a62345a7d8a42199.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libminiz_oxide-db5f21836df1d8ae.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libadler-9f21871e5221501a.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/librustc_std_workspace_alloc-288ed4fa2a08c0e9.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libunwind-38fdae42d1315457.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libcfg_if-14a890fc8e331c29.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/liblibc-1cd46bbe1fa300e9.rlib" "-l" "c" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/liballoc-1c2004caac219938.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/librustc_std_workspace_core-1fbc4eaf09b3d6fd.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libcore-41d052a032f91e0b.rlib" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libcompiler_builtins-61af768e1b976a69.rlib" "-L" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib" "-L" "/Users/wujunzhuo/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/self-contained" "-o" "/Users/wujunzhuo/Desktop/hello/wasm/target/wasm32-wasi/release/deps/hello.wasm" "--gc-sections" "--no-entry" "-O3" "-mexec-model=reactor"
= note: rust-lld: error: invalid target architecture: exec-model=reactor
error: could not compile `hello` due to previous errorIs there any mistake? |
|
Try adding |
Still not work... Alright, I'll close this pr, and open a new issue in the Rust toolchain community. |
No description provided.