From 45b29031ae7954a0f2d154d0b5f9d33dcf5da840 Mon Sep 17 00:00:00 2001 From: Peter Nose Date: Thu, 12 Dec 2024 12:09:55 +0100 Subject: [PATCH] go/runtime/bundle: Close zip file if Open fails --- go/runtime/bundle/bundle.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/go/runtime/bundle/bundle.go b/go/runtime/bundle/bundle.go index 534d9adc58b..4505b0b9ffa 100644 --- a/go/runtime/bundle/bundle.go +++ b/go/runtime/bundle/bundle.go @@ -518,13 +518,19 @@ func (bnd *Bundle) Close() error { } // Open opens and validates a runtime bundle instance. -func Open(fn string, opts ...OpenOption) (*Bundle, error) { +func Open(fn string, opts ...OpenOption) (_ *Bundle, err error) { options := NewOpenOptions(opts...) + // Open the zip file and close it on error. r, err := zip.OpenReader(fn) if err != nil { return nil, fmt.Errorf("runtime/bundle: failed to open bundle: %w", err) } + defer func() { + if err != nil { + r.Close() + } + }() // Read the contents. data := make(map[string]Data)