Skip to content

Commit

Permalink
Merge pull request #14 from mattn/close-file
Browse files Browse the repository at this point in the history
Close file
  • Loading branch information
moriyoshi authored Jun 28, 2020
2 parents a95a3c1 + a49cc74 commit d2eb929
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ func (ctx *ConfigReaderContext) extractCertPool(certPoolConfig interface{}, path
return nil, errors.Errorf("%s: failed to open %s", ctx.Filename, fileOrDirectory)
}
if err == nil {
defer f.Close()

var traverse func(f *os.File) error
traverse = func(f *os.File) error {
st, err := f.Stat()
Expand All @@ -425,6 +427,7 @@ func (ctx *ConfigReaderContext) extractCertPool(certPoolConfig interface{}, path
if err != nil {
return errors.Wrapf(err, "%s: failed to open %s", ctx.Filename, cp)
}
defer cf.Close()
err = traverse(cf)
if err != nil {
return err
Expand Down Expand Up @@ -576,6 +579,8 @@ func (ctx *ConfigReaderContext) extractCertPrivateKeyPairs(certConfigMap map[int
return
}
if err == nil {
defer f.Close()

var pemBytes []byte
pemBytes, err = ioutil.ReadAll(f)
if err != nil {
Expand Down Expand Up @@ -645,6 +650,8 @@ func (ctx *ConfigReaderContext) extractCertPrivateKeyPairs(certConfigMap map[int
return
}
if err == nil {
defer f.Close()

var pemBytes []byte
pemBytes, err = ioutil.ReadAll(f)
if err != nil {
Expand Down Expand Up @@ -1034,6 +1041,8 @@ func loadConfig(yamlFile string, progname string) (*Config, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to load %s", yamlFile)
}
defer f.Close()

configMap := make(map[string]interface{})
err = yaml.NewDecoder(f).Decode(&configMap)
if err != nil {
Expand Down

0 comments on commit d2eb929

Please sign in to comment.