This is an automated email from the ASF dual-hosted git repository. yuchanns pushed a commit to branch fix-go-use-after-free in repository https://gitbox.apache.org/repos/asf/opendal.git
commit 540434d9586a884e19feeb03fa949465d9a4b9f0 Author: Hanchin Hsieh <[email protected]> AuthorDate: Thu Jul 10 11:51:06 2025 +0800 fix(bindings/go): ffi calls use after free --- bindings/go/opendal.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindings/go/opendal.go b/bindings/go/opendal.go index ab2777878..02845bd28 100644 --- a/bindings/go/opendal.go +++ b/bindings/go/opendal.go @@ -175,6 +175,13 @@ func NewOperator(scheme Scheme, opts OperatorOptions) (op *Operator, err error) if err != nil { return } + defer func() { + if err != nil { + // cancel must be called after any ffi calls + // to prevent `use after free` panics. + cancel() + } + }() options := ffiOperatorOptionsNew.symbol(ctx)() setOptions := ffiOperatorOptionsSet.symbol(ctx) @@ -190,7 +197,6 @@ func NewOperator(scheme Scheme, opts OperatorOptions) (op *Operator, err error) inner, err := ffiOperatorNew.symbol(ctx)(scheme, options) if err != nil { - cancel() return }
