plugin/file: fix file leak (#5687)

This commit is contained in:
Yong Tang 2022-10-11 14:49:52 -04:00 committed by GitHub
parent 26aae951e7
commit c6a543551e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -93,18 +93,27 @@ func fileParse(c *caddy.Controller) (Zones, error) {
openErr = err openErr = err
} }
err = func() error {
defer reader.Close()
for i := range origins { for i := range origins {
z[origins[i]] = NewZone(origins[i], fileName) z[origins[i]] = NewZone(origins[i], fileName)
if openErr == nil { if openErr == nil {
reader.Seek(0, 0) reader.Seek(0, 0)
zone, err := Parse(reader, origins[i], fileName, 0) zone, err := Parse(reader, origins[i], fileName, 0)
if err != nil { if err != nil {
return Zones{}, err return err
} }
z[origins[i]] = zone z[origins[i]] = zone
} }
names = append(names, origins[i]) names = append(names, origins[i])
} }
return nil
}()
if err != nil {
return Zones{}, err
}
for c.NextBlock() { for c.NextBlock() {
switch c.Val() { switch c.Val() {