1
0
mirror of https://github.com/golang/go synced 2024-09-30 14:28:33 -06:00

godoc/vfs: close file on error

When Stat() or IsDir() return errors, close the file to avoid a leak.

Change-Id: I46d5e34c3443413ca674f2a703d033d945c21efa
Reviewed-on: https://go-review.googlesource.com/10557
Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
Gustav Paul 2015-05-31 20:34:06 +02:00 committed by Minux Ma
parent 8ccf558e8a
commit 68353d2750

View File

@ -42,9 +42,11 @@ func (root osFS) Open(path string) (ReadSeekCloser, error) {
}
fi, err := f.Stat()
if err != nil {
f.Close()
return nil, err
}
if fi.IsDir() {
f.Close()
return nil, fmt.Errorf("Open: %s is a directory", path)
}
return f, nil