Add error check to avoid panic (#4584)

* Add error check to avoid panic

Signed-off-by: Cookie Wang <luckymrwang@163.com>

* Add error check to avoid panic

Signed-off-by: Cookie Wang <luckymrwang@163.com>

Co-authored-by: Cookie Wang <luckymrwang@163.com>
This commit is contained in:
wangchenglong01 2021-05-04 16:08:06 +08:00 committed by GitHub
parent 40edf1e566
commit b881a1ef13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -117,11 +117,14 @@ func (h *Hostsfile) readHosts() {
defer file.Close()
stat, err := file.Stat()
if err != nil {
return
}
h.RLock()
size := h.size
h.RUnlock()
if err == nil && h.mtime.Equal(stat.ModTime()) && size == stat.Size() {
if h.mtime.Equal(stat.ModTime()) && size == stat.Size() {
return
}