Skip to content

Fix Wasm2JSBuilder leaking temporary Function #3098

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

Merged
merged 2 commits into from
Sep 3, 2020

Conversation

dcodeIO
Copy link
Contributor

@dcodeIO dcodeIO commented Sep 2, 2020

Fixes Wasm2JSBuilder leaking a temporary Function (WASM_FETCH_HIGH_BITS) in Wasm2JSBuilder::processWasm. The function is created to be converted to JS, but is not actually part of the module, so it either needs to be cleaned up separately or be added to the module. This PR does the latter in case it is useful.

@dcodeIO
Copy link
Contributor Author

dcodeIO commented Sep 2, 2020

The alternative here is to actually add the function to the module, which might potentially be useful if someone wants to print the module after conversion? Is that a valid scenario?

src/wasm2js.h Outdated
@@ -424,13 +424,13 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) {
});
if (generateFetchHighBits) {
Builder builder(allocator);
asmFunc[3]->push_back(processFunction(
wasm,
std::unique_ptr<Function> tempFunc(
Copy link
Member

Choose a reason for hiding this comment

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

Since this Function only lives for a very short scope, I think we should be able to just stack allocate it, avoiding the unique_ptr (and even the builder) entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opted for adding the function to the module now. generateFetchHighBits should already ensure that it isn't added twice iiuc. Also, there are other functions already being added if I'm not mistaken, like from i64 lowering, so this should be fine and one can inspect the module afterwards to see exactly what became converted if needed.

@tlively
Copy link
Member

tlively commented Sep 2, 2020

Adding the function to the modules sounds ok, too, as long as it doesn't get processed twice or something.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

👍

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.

2 participants