From cfe6c55d0630174a3674d28d39877ccc26e034de Mon Sep 17 00:00:00 2001 From: "Edman P. Anjos" Date: Fri, 27 Dec 2024 22:35:11 +0100 Subject: [PATCH] fix: Do not close wazero module on error (#3758) (#3759) 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. --- internal/ext/wasm/wasm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ext/wasm/wasm.go b/internal/ext/wasm/wasm.go index a14c71d8a4..58384a9c95 100644 --- a/internal/ext/wasm/wasm.go +++ b/internal/ext/wasm/wasm.go @@ -222,7 +222,7 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any, } result, err := runtimeAndCode.rt.InstantiateModule(ctx, runtimeAndCode.code, conf) - if result != nil { + if err == nil { defer result.Close(ctx) } if cerr := checkError(err, stderr); cerr != nil {