Repository navigation
Throw when Global.SetValue fails instead of ignoring the error - #393
Merged
martindevans merged 1 commit intoNov 3, 2026
Merged
Conversation
`wasmtime_global_set` returns a `wasmtime_error_t*`, but the binding declared it as returning `void`. Errors such as setting a funcref from another store were silently dropped and leaked. `Global.SetValue` and `Global.Accessor<T>.SetValue` now throw a `WasmtimeException`, matching `Table.SetElement`.
martindevans
approved these changes
Nov 3, 2026
martindevans
left a comment
Member
There was a problem hiding this comment.
Thanks for investigating and fixing this 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wasmtime_global_setreturns awasmtime_error_t*, but the P/Invoke inGlobal.Nativedeclares it asvoid. When the native call fails, the error is dropped and its allocation leaks, soGlobal.SetValueandGlobal.Accessor<T>.SetValuereturn normally even though the global keeps its old value.One way to trigger this is to set a funcref global to a
Functionthat belongs to a differentStore.Table.SetElementthrows aWasmtimeExceptionin that case.Global.SetValuethrows nothing and leaves the global unchanged.Fixes #392.
Changes
wasmtime_global_setas returningIntPtr, matchinginclude/wasmtime/global.h.Global.SetValueandGlobal.Accessor<T>.SetValue, throwWasmtimeException.FromOwnedErrorwhen the call returns an error.Table.SetElementalready handles errors the same way.WasmtimeExceptionand check that the global still holds a null funcref.Testing
dotnet test tests/Wasmtime.Tests.csproj --filter "FullyQualifiedName~GlobalImportBindingTests": before the fix, the 2 new tests fail with "no exception was thrown". After the fix, all 14 tests pass.dotnet test tests/Wasmtime.Tests.csproj: 479 passed, 2 skipped, 0 failed (Linux x64, net9.0).