mirror of
https://github.com/golang/go
synced 2024-11-05 11:36:10 -07: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:
parent
8ccf558e8a
commit
68353d2750
@ -42,9 +42,11 @@ func (root osFS) Open(path string) (ReadSeekCloser, error) {
|
|||||||
}
|
}
|
||||||
fi, err := f.Stat()
|
fi, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
f.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
|
f.Close()
|
||||||
return nil, fmt.Errorf("Open: %s is a directory", path)
|
return nil, fmt.Errorf("Open: %s is a directory", path)
|
||||||
}
|
}
|
||||||
return f, nil
|
return f, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user