funcs: defer close file in funcs

Files opened by these two functions were not being closed,
leaking file descriptors. Close files that were opened when the
function exist.
This commit is contained in:
Simão Gomes Viana 2021-11-11 14:32:10 +01:00 committed by Simao Gomes Viana
parent 388c430ece
commit 5bbd108572
No known key found for this signature in database
GPG Key ID: 2B861A352E0B987F
2 changed files with 2 additions and 0 deletions

View File

@ -248,6 +248,7 @@ func makeFileHashFunction(baseDir string, hf func() hash.Hash, enc func([]byte)
if err != nil {
return cty.UnknownVal(cty.String), err
}
defer f.Close()
h := hf()
_, err = io.Copy(h, f)

View File

@ -377,6 +377,7 @@ func readFileBytes(baseDir, path string) ([]byte, error) {
}
return nil, err
}
defer f.Close()
src, err := ioutil.ReadAll(f)
if err != nil {