From b2940955ab8b26e19d43a43c4da0475dd81bdb56 Mon Sep 17 00:00:00 2001 From: miraclesu Date: Mon, 25 Jan 2016 14:19:23 +0800 Subject: [PATCH] fix reader nil pointer --- tail.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tail.go b/tail.go index 307a026..6f77661 100644 --- a/tail.go +++ b/tail.go @@ -143,11 +143,17 @@ func (tail *Tail) Tell() (offset int64, err error) { return } offset, err = tail.file.Seek(0, os.SEEK_CUR) - if err == nil { - tail.lk.Lock() - offset -= int64(tail.reader.Buffered()) - tail.lk.Unlock() + if err != nil { + return } + + tail.lk.Lock() + defer tail.lk.Unlock() + if tail.reader == nil { + return + } + + offset -= int64(tail.reader.Buffered()) return }