Skip to content

Commit f97b4af

Browse files
authored
(fix) declCfg non-closed file descriptor (#1625)
1 parent e6d2c99 commit f97b4af

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

alpha/declcfg/load.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,20 @@ func parseMetaPaths(ctx context.Context, root fs.FS, pathChan <-chan string, wal
183183
if !ok {
184184
return nil
185185
}
186-
file, err := root.Open(path)
186+
err := func() error { // using closure to ensure file is closed immediately after use
187+
file, err := root.Open(path)
188+
if err != nil {
189+
return err
190+
}
191+
defer file.Close()
192+
193+
return WalkMetasReader(file, func(meta *Meta, err error) error {
194+
return walkFn(path, meta, err)
195+
})
196+
}()
187197
if err != nil {
188198
return err
189199
}
190-
if err := WalkMetasReader(file, func(meta *Meta, err error) error {
191-
return walkFn(path, meta, err)
192-
}); err != nil {
193-
return err
194-
}
195200
}
196201
}
197202
}

0 commit comments

Comments
 (0)