Spot the bug in batch digest

from defer, panic and recover
Go 1.27 intermediate 4 min 2 issues to find

Find the resource-lifetime problems in this batch digest function.

Go
func digestAll(paths []string) error {
    for _, path := range paths {
        file, err := os.Open(path)
        if err != nil {
            return err
        }
        defer file.Close()
        if err := digest(file); err != nil {
            return err
        }
    }
    return nil
}
Open in playground
Report an error