From 453ece641539a448b73c477544a179b483207273 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 2 Feb 2021 13:49:41 +0100 Subject: [PATCH 1/3] fix(c-api) Call `wasi_env_delete` manually. `wasi_get_imports` isn't taking ownership of `wasi_env_t` (despites what is written in the documentation). And it must not take ownership of it, since one could use it with the `wasi_env_read_stdout` & sibling functions after having called `wasi_get_imports`. Consequently, this patch calls `wasi_env_delete` to avoid leaking memory. --- lib/c-api/tests/test-wasi.c | 1 + lib/cli/src/commands/wasmer_create_exe_main.c | 1 + lib/engine-object-file/README.md | 1 + tests/integration/cli/tests/object_file_engine_test_c_source.c | 1 + 4 files changed, 4 insertions(+) diff --git a/lib/c-api/tests/test-wasi.c b/lib/c-api/tests/test-wasi.c index 3403e8996b7..07db457e1de 100644 --- a/lib/c-api/tests/test-wasi.c +++ b/lib/c-api/tests/test-wasi.c @@ -161,6 +161,7 @@ int main(int argc, const char* argv[]) { // Shut down. printf("Shutting down...\n"); + wasi_env_delete(wasi_env); wasm_func_delete(run_func); wasi_env_delete(wasi_env); wasm_store_delete(store); diff --git a/lib/cli/src/commands/wasmer_create_exe_main.c b/lib/cli/src/commands/wasmer_create_exe_main.c index 73300da587a..131efbf6a39 100644 --- a/lib/cli/src/commands/wasmer_create_exe_main.c +++ b/lib/cli/src/commands/wasmer_create_exe_main.c @@ -143,6 +143,7 @@ int main(int argc, char* argv[]) { #ifdef WASI bool get_imports_result = wasi_get_imports(store, module, wasi_env, &imports); + wasi_env_delete(wasi_env); if (!get_imports_result) { fprintf(stderr, "Error getting WASI imports!\n"); diff --git a/lib/engine-object-file/README.md b/lib/engine-object-file/README.md index cf5547c9e8a..02c7ee12aa9 100644 --- a/lib/engine-object-file/README.md +++ b/lib/engine-object-file/README.md @@ -87,6 +87,7 @@ int main() { wasm_importtype_vec_delete(&import_types); bool get_imports_result = wasi_get_imports(store, module, wasi_env, imports); + wasi_env_delete(wasi_env); if (!get_imports_result) { printf("> Error getting WASI imports!\n"); print_wasmer_error(); diff --git a/tests/integration/cli/tests/object_file_engine_test_c_source.c b/tests/integration/cli/tests/object_file_engine_test_c_source.c index 977b6d580c8..f39b8620748 100644 --- a/tests/integration/cli/tests/object_file_engine_test_c_source.c +++ b/tests/integration/cli/tests/object_file_engine_test_c_source.c @@ -63,6 +63,7 @@ int main() { wasm_importtype_vec_delete(&import_types); bool get_imports_result = wasi_get_imports(store, module, wasi_env, &imports); + wasi_env_delete(wasi_env); if (!get_imports_result) { printf("> Error getting WASI imports!\n"); From 193afc81d58449f2ec1043fe50848826648abd16 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 2 Feb 2021 16:02:35 +0100 Subject: [PATCH 2/3] doc(changelog) Add #2090. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30388c12a86..53296cf0b34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [#2056](https://github.com/wasmerio/wasmer/pull/2056) Change back to depend on the `enumset` crate instead of `wasmer_enumset` ### Fixed +- [#2090](https://github.com/wasmerio/wasmer/pull/2090) `wasi_env_t` needs to be freed with `wasi_env_delete` in the C API. - [#2084](https://github.com/wasmerio/wasmer/pull/2084) Avoid calling the function environment finalizer more than once when the environment has been cloned in the C API. - [#2069](https://github.com/wasmerio/wasmer/pull/2069) Use the new documentation for `include/README.md` in the Wasmer package. - [#2042](https://github.com/wasmerio/wasmer/pull/2042) Parse more exotic environment variables in `wasmer run`. From 6800315024f4c6b5f971a2839a0b9c2045c51aa5 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 2 Feb 2021 17:23:36 +0100 Subject: [PATCH 3/3] test(c-api) Remove a double-free. --- lib/c-api/tests/test-wasi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/c-api/tests/test-wasi.c b/lib/c-api/tests/test-wasi.c index 07db457e1de..3403e8996b7 100644 --- a/lib/c-api/tests/test-wasi.c +++ b/lib/c-api/tests/test-wasi.c @@ -161,7 +161,6 @@ int main(int argc, const char* argv[]) { // Shut down. printf("Shutting down...\n"); - wasi_env_delete(wasi_env); wasm_func_delete(run_func); wasi_env_delete(wasi_env); wasm_store_delete(store);