Skip to content

Commit

Permalink
Merge #2090
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bors[bot] and Hywan authored Feb 2, 2021
2 parents 3ed1e47 + 6800315 commit 820ffe9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions lib/cli/src/commands/wasmer_create_exe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions lib/engine-object-file/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 820ffe9

Please sign in to comment.