mirror of
https://github.com/costela/docker-etchosts.git
synced 2025-05-11 01:45:40 +02:00
close tmpfile before removing to avoid fd leak
This commit is contained in:
parent
2c93f8b233
commit
06d16b7b51
1 changed files with 5 additions and 5 deletions
10
etchosts.go
10
etchosts.go
|
@ -32,12 +32,12 @@ func writeToEtcHosts(ipsToNames ipsToNamesMap, config ConfigSpec) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove tempfile; this might fail if we managed to move it, which is ok
|
// remove tempfile; this might fail if we managed to move it, which is ok
|
||||||
defer func(path string) {
|
defer func(file *os.File) {
|
||||||
err := os.Remove(path)
|
file.Close()
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(file.Name()); err != nil && !os.IsNotExist(err) {
|
||||||
log.Warnf("unexpected error trying to remove temp file %s: %s", path, err)
|
log.Warnf("unexpected error trying to remove temp file %s: %s", file.Name(), err)
|
||||||
}
|
}
|
||||||
}(tmp.Name())
|
}(tmp)
|
||||||
|
|
||||||
// go through file and update existing entries/prune nonexistent entries
|
// go through file and update existing entries/prune nonexistent entries
|
||||||
managedLine := false
|
managedLine := false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue