Skip to content

Commit e437607

Browse files
committed
fix: Do not close wazero module on error (#3758)
wazero takes care not to leak modules when `InstantiateModule` returns an error. This means that sqlc will call `result.Close` a second time if a non nil module was returned, which causes a segfault.
1 parent 7700b5a commit e437607

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

internal/ext/wasm/wasm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
222222
}
223223

224224
result, err := runtimeAndCode.rt.InstantiateModule(ctx, runtimeAndCode.code, conf)
225-
if result != nil {
226-
defer result.Close(ctx)
227-
}
228225
if cerr := checkError(err, stderr); cerr != nil {
229226
return cerr
230227
}
228+
if result != nil {
229+
defer result.Close(ctx)
230+
}
231231

232232
// Print WASM stdout
233233
stdoutBlob := stdout.Bytes()

0 commit comments

Comments
 (0)