Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in wat2wasm function #1855

Merged
merged 6 commits into from
Dec 1, 2020
Merged

Conversation

MarkMcCaskey
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey commented Dec 1, 2020

Alternative to #1853 ;

Found with @nlewycky

Review

  • Add a short description of the the change to the CHANGELOG.md file

@MarkMcCaskey MarkMcCaskey force-pushed the fix/capi-wat2wasm-mem-leak branch from 42af38d to deec77d Compare December 1, 2020 19:41
Comment on lines 16 to 19
Err(err) => {
crate::error::update_last_error(err);
return;
}
Copy link
Contributor

@nlewycky nlewycky Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the caller know whether wat2wasm succeeded? Is there a way to initialize a wasm_byte_vec_t to "clear" which the user can then test for? Or does it always check for errors with a separate "did the last thing fail" call after every call to wat2wasm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point, in this case I'd assume the user would initialize to null prior and check for that, but perhaps it makes more sense for us to zero the fields for them on failure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use the return value if you like.

lib/c-api/tests/wasm_c_api/test-wat2wasm.c Outdated Show resolved Hide resolved
lib/c-api/wasmer_wasm.h Outdated Show resolved Hide resolved
@@ -237,8 +237,8 @@ int wasmer_last_error_message(char *buffer, int length);
* Parses in-memory bytes as either the WAT format, or a binary Wasm
* module. This is wasmer-specific.
*
* In case of failure, `wat2wasm` returns `NULL`.
* In case of failure, `wat2wasm` fills the `out->data = NULL` and `out->size = 0`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar here is a little off, but meh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it!

@MarkMcCaskey
Copy link
Contributor Author

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 1, 2020

@bors bors bot merged commit 774a4e6 into master Dec 1, 2020
@bors bors bot deleted the fix/capi-wat2wasm-mem-leak branch December 1, 2020 22:33
@Hywan
Copy link
Contributor

Hywan commented Dec 3, 2020

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants