Skip to content

Commit

Permalink
go/runtime/bundle: Close zip file if Open fails
Browse files Browse the repository at this point in the history
  • Loading branch information
peternose committed Dec 12, 2024
1 parent b3704ef commit 45b2903
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion go/runtime/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 45b2903

Please sign in to comment.