-
Notifications
You must be signed in to change notification settings - Fork 288
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
runtime.InstantiateModule
sometimes returns a "struct-wrapped" nil
value, instead of returning actual nil
.
More specifically, this line https://github.com/tetratelabs/wazero/blob/main/runtime.go#L318 assigns mod
and returns it implicitly on L324.
This allows code like the following to panic with a nil pointer dereference because m
is nil
:
m, _ := r.InstantiateModule(ctx, compiled, config)
if m != nil { // this check passes
defer m.Close() // and yet this causes a nil pointer dereference
}
To Reproduce
Here is an example that mimics wazero's behavior: https://go.dev/play/p/66QShXidalq
Expected behavior
From https://go.dev/doc/faq#nil_error, the FAQ recommends:
To return a proper nil error to the caller, the function must return an explicit nil
Additional context
Found on sqlc-dev/sqlc#3759 (comment)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working