-
Notifications
You must be signed in to change notification settings - Fork 824
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
Conversation
42af38d
to
deec77d
Compare
lib/c-api/src/wasm_c_api/wat.rs
Outdated
Err(err) => { | ||
crate::error::update_last_error(err); | ||
return; | ||
} |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Co-authored-by: nlewycky <[email protected]>
Co-authored-by: nlewycky <[email protected]>
lib/c-api/wasmer_wasm.h
Outdated
@@ -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`. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it!
bors r+ |
👍 |
Alternative to #1853 ;
Found with @nlewycky
Review