Skip to content

Commit 820ffe9

Browse files
bors[bot]Hywan
andauthored
Merge #2090
2090: fix(c-api) Call `wasi_env_delete` manually r=Hywan a=Hywan # Description `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. # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2 parents 3ed1e47 + 6800315 commit 820ffe9

File tree

4 files changed

+4
-0
lines changed

4 files changed

+4
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [#2056](https://github.com/wasmerio/wasmer/pull/2056) Change back to depend on the `enumset` crate instead of `wasmer_enumset`
2121

2222
### Fixed
23+
- [#2090](https://github.com/wasmerio/wasmer/pull/2090) `wasi_env_t` needs to be freed with `wasi_env_delete` in the C API.
2324
- [#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.
2425
- [#2069](https://github.com/wasmerio/wasmer/pull/2069) Use the new documentation for `include/README.md` in the Wasmer package.
2526
- [#2042](https://github.com/wasmerio/wasmer/pull/2042) Parse more exotic environment variables in `wasmer run`.

lib/cli/src/commands/wasmer_create_exe_main.c

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ int main(int argc, char* argv[]) {
143143

144144
#ifdef WASI
145145
bool get_imports_result = wasi_get_imports(store, module, wasi_env, &imports);
146+
wasi_env_delete(wasi_env);
146147

147148
if (!get_imports_result) {
148149
fprintf(stderr, "Error getting WASI imports!\n");

lib/engine-object-file/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ int main() {
8787
wasm_importtype_vec_delete(&import_types);
8888

8989
bool get_imports_result = wasi_get_imports(store, module, wasi_env, imports);
90+
wasi_env_delete(wasi_env);
9091
if (!get_imports_result) {
9192
printf("> Error getting WASI imports!\n");
9293
print_wasmer_error();

tests/integration/cli/tests/object_file_engine_test_c_source.c

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ int main() {
6363
wasm_importtype_vec_delete(&import_types);
6464

6565
bool get_imports_result = wasi_get_imports(store, module, wasi_env, &imports);
66+
wasi_env_delete(wasi_env);
6667

6768
if (!get_imports_result) {
6869
printf("> Error getting WASI imports!\n");

0 commit comments

Comments
 (0)