grandpig opened PR #14126 from grandpig:fix-linker-callback-finalizers to bytecodealliance:main:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->Follow-up to bytecodealliance/wasmtime-go#293.
When one of the linker function APIs receives an invalid UTF-8 module or function name,
to_str!returns an error before the Rust callback closure is constructed.The closure owns the C-provided
dataandfinalizerthroughForeignData.Constructing it after parsing the names therefore means that the finalizer is not called when name parsing fails.
Move callback construction before UTF-8 validation in:
wasmtime_linker_define_funcwasmtime_linker_define_func_uncheckedwasmtime_linker_define_async_funcThis transfers ownership of
datatoForeignDatabefore any fallible name parsing. If parsing fails, normal Rust drop behavior invokes the finalizer.Regression tests verify this behavior for the checked, unchecked, and async linker function APIs.
Testing
- C API test suite: 137/137 passed
cargo fmt --all -- --check- clang-format dry run on the modified C++ test files
grandpig requested dicej for a review on PR #14126.
grandpig requested wasmtime-core-reviewers for a review on PR #14126.
:thumbs_up: dicej submitted PR review:
Thanks!
dicej has enabled auto merge for PR #14126.
dicej added PR #14126 Run linker callback finalizers on invalid names to the merge queue.
:check: dicej merged PR #14126.
dicej removed PR #14126 Run linker callback finalizers on invalid names from the merge queue.
Last updated: Aug 30 2026 at 09:07 UTC