Skip to content

Commit

Permalink
fix: file descriptor leak in the configuration tree load (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
i4ki committed May 8, 2023
1 parent be4e424 commit d902205
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion config/config.go
Expand Up @@ -378,7 +378,7 @@ func (l List[T]) Len() int { return len(l) }
func (l List[T]) Less(i, j int) bool { return l[i].Dir().String() < l[j].Dir().String() }
func (l List[T]) Swap(i, j int) { l[i], l[j] = l[j], l[i] }

func loadTree(rootdir string, cfgdir string, rootcfg *hcl.Config) (*Tree, error) {
func loadTree(rootdir string, cfgdir string, rootcfg *hcl.Config) (_ *Tree, err error) {
logger := log.With().
Str("action", "config.loadTree()").
Str("dir", rootdir).
Expand All @@ -389,6 +389,10 @@ func loadTree(rootdir string, cfgdir string, rootcfg *hcl.Config) (*Tree, error)
return nil, errors.E(err, "failed to open cfg directory")
}

defer func() {
err = errors.L(err, f.Close()).AsError()
}()

logger.Trace().Msg("reading directory file names")

names, err := f.Readdirnames(0)
Expand Down

0 comments on commit d902205

Please sign in to comment.