Skip to content

go: free ONNX model path C string - #1446

Open
ryux1 wants to merge 1 commit into
google:mainfrom
ryux1:fix/free-onnx-model-path
Open

ryux1 wants to merge 1 commit into
google:mainfrom
ryux1:fix/free-onnx-model-path

Conversation

@ryux1

@ryux1 ryux1 commented Sep 7, 2026

Copy link
Copy Markdown

Summary

Keep the C.CString used for the ONNX model path in a local variable and release it after CreateSession returns. The deferred C.free covers both the successful and error paths.

This intentionally leaves the separately reported ONNX-owned environment, options, and status cleanup out of scope.

Fixes #1444

Testing

Using Go 1.22.3 and ONNX Runtime 1.19.2 with the versions, linker flags, assets, and SHA-256 digest pinned by the repository:

  • go test ./...
  • go vet ./...
  • go vet -tags onnxruntime ./...
  • go test -v -tags onnxruntime -ldflags="-linkmode=external -extldflags=-L/opt/onnxruntime/lib" ./...
  • go build -tags onnxruntime -ldflags="-linkmode=external -extldflags=-L/opt/onnxruntime/lib" . from go/cli

@ryux1

ryux1 commented Sep 17, 2026 •

Copy link
Copy Markdown
Author

Rebased onto the current main (9096fd3) and revalidated the change locally.

Passed:

  • go test ./...
  • go vet ./...
  • go vet -tags onnxruntime ./...
  • full go test -v -tags onnxruntime ./... with ONNX Runtime 1.19.2 and the standard_v3_3 assets
  • tagged CLI build

NewOnnx passed a C.CString allocation inline to CreateSession, leaving no pointer available to release on either success or error.

Keep the Go-owned C string in a local variable and defer C.free after the C call has finished using it. ONNX-owned session resources remain outside this change.
@ryux1
ryux1 force-pushed the fix/free-onnx-model-path branch from 65e619d to 9f23433 Compare October 8, 2026 21:17
@ryux1

ryux1 commented Oct 8, 2026

Copy link
Copy Markdown
Author

Apologies for the delayed follow-up. I refreshed the single focused commit onto the current main today; the PR is mergeable, the current hosted scan and CLA checks pass, and the previously documented Go, vet, tagged ONNX, and CLI validations remain the relevant contributor-side evidence. The change is still limited to releasing the Go-owned model-path C string, with ONNX-owned cleanup intentionally out of scope. This is ready for a code-owner review when convenient.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible memory leak: model path C.CString is never freed in NewOnnx

1 participant